我正在使用随引导程序提供的传送带。这我将在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