且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP:中断循环,然后继续吗?

更新时间:2022-03-14 05:44:51

尝试一下

<?php
while ($wp_query->have_posts()) :
    $wp_query->the_post(); 
    if($wp_query->current_post <= 1){ ?>
        <div class="x">
        .. post 1
        </div>
        <div class="wrap"> <!-- should be only once -->
    <?php 
    $is_wrapped = 1;
    }
    if($wp_query->current_post > 1){ ?>
        <div class="y">
          .. post 2, then post 3, ...
        </div>
    <?php } 
endwhile;?>
<?php if (!empty($is_wrapped)){ ?>
        </div><!-- should be only once -->
<?php } ?>