我在这里有一个循环,它发布了我的自定义帖子类型的完整列表-但是,我正在尝试打印一个clearfix的每个第4个循环,这是我想到的,但是它要么在每个循环中打印一次,要么根本不打印-有人可以帮忙吗?干杯
<?php
$args = array(
'post_type' => 'custom',
'numberposts' => '-1',
'post_status' => 'publish',
'order' => 'ASC'
);
$postslist = get_posts($args);
foreach ($postslist as $post) :
setup_postdata($post);
for ($counter = 1; $counter < 100; $counter++ ) {
if ($counter % 4 == 0) {
echo "<div class='clearfix'></div>";
}
}
?>
不需要for循环。您可以尝试一下,希望它能起作用。
<?php
$args = array(
'post_type' => 'custom',
'numberposts' => '-1',
'post_status' => 'publish',
'order' => 'ASC'
);
$postslist = get_posts($args);
$count = 1 ;
foreach ($postslist as $post) :
setup_postdata($post);
if($count % 4 ==0){
echo '<div class="clear"></div>';
}
$count++;
endforeach; ?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句