尝试在 Wordpress 中每 4 个循环打印一个 div
Trying to print a div every 4th loop in Wordpress
我这里有一个循环,它发布了我的自定义 post 类型的完整列表 - 但是,每第 4 个循环我试图打印一个 clearfix,这是我想出的,但它要么在每个循环或 none 打印它 - 有人可以伸出援手吗?干杯
<?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; ?>
我这里有一个循环,它发布了我的自定义 post 类型的完整列表 - 但是,每第 4 个循环我试图打印一个 clearfix,这是我想出的,但它要么在每个循环或 none 打印它 - 有人可以伸出援手吗?干杯
<?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; ?>