我试图让我的柜台,以及计数。我想添加一个类名(偶数)到每一秒后用下面显示的:在php中使用foreach的计数器
<?php
global $paged;
global $post;
$do_not_duplicate = array();
$categories = get_the_category();
$category = $categories[0];
$cat_ID = $category->cat_ID;
$myposts = get_posts('category='.$cat_ID.'&paged='.$paged);
$do_not_duplicate[] = $post->ID;
$c = 0;
$c++;
if($c == 2) {
$style = 'even animated fadeIn';
$c = 0;
}
else $style='animated fadeIn';
?>
<?php foreach($myposts as $post) :?>
// Posts outputted here
<?php endforeach; ?>
我只是不明白被输出的even
类名。这得到输出的唯一的类名是animated
和FadeIn
类(从我的if语句else部分)被添加到每一个岗位,此刻与
使用模运算符:'如果(($ C++%2)== 0){'但是在你的foreach循环中做'内部' – 2013-03-18 15:40:57
'$ c'看起来像它总是1.你可能想把你的if语句移到你的'foreach'中。 – Jrod 2013-03-18 15:43:05