我正在使用隨引導程序提供的傳送帶。這我將在WordPress中使用。我用foreach循環查詢兩個最近發佈的帖子,但爲了使輪播正常工作,我需要最新的帖子來有一個額外的「主動」類。我在這裏找到了一些解決方案,但它都是while循環,我真的需要這個foreach循環。這是我的代碼:向(foreach)循環中的第一個div添加一個類
<div id="NewsCarousel" class="carousel slide">
<div class="carousel-inner">
<?php
$args = array('numberposts' => '2', 'category' => 5);
$recent_posts = wp_get_recent_posts($args);
foreach($recent_posts as $recent){
echo '<div class="item"><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . get_the_post_thumbnail($recent["ID"], array(200,200)) .$recent["post_title"].'</a> </div> ';
}
?>
</div>
</div>
循環類型應該沒有關係,添加一個計數器,第一次迭代添加類 – 2014-01-05 22:31:33
...或者使用'$ recent_posts'數組鍵,如果它們保證爲零基於 – zerkms