尝试在Wordpress中每隔4个循环打印一个div
我这里有一个循环,它发布了我自定义帖子类型的完整列表-然而,每四个循环我都试图打印一个clearfix,这是我想到的,但它要么打印每个循环,要么根本不打印-有人能帮忙吗?干杯尝试在Wordpress中每隔4个循环打印一个div,wordpress,loops,counter,Wordpress,Loops,Counter,我这里有一个循环,它发布了我自定义帖子类型的完整列表-然而,每四个循环我都试图打印一个clearfix,这是我想到的,但它要么打印每个循环,要么根本不打印-有人能帮忙吗?干杯 <?php $args = array( 'post_type' => 'custom', 'numberposts' => '-1', 'post_status' => 'publish', 'order' => 'ASC' ); $
<?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; ?>
不幸的是,这无法打印div对不起,我忘记了$count++。你能再试一次吗