Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试在Wordpress中每隔4个循环打印一个div_Wordpress_Loops_Counter - Fatal编程技术网

尝试在Wordpress中每隔4个循环打印一个div

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

我这里有一个循环,它发布了我自定义帖子类型的完整列表-然而,每四个循环我都试图打印一个clearfix,这是我想到的,但它要么打印每个循环,要么根本不打印-有人能帮忙吗?干杯

<?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++。你能再试一次吗