Quantcast
Channel: User Michael - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 44

Answer by Michael for Continue or break the while loop

$
0
0

'break' is the right keyword...code structure below, no custom query needed if used in a standard template.

<?php    $posts_per_first_section = 6; //how many posts you want to show in the first section//    if ( have_posts() ) :        ?><!-- opening html for first loop --><?php        /* Start the Loop */        while ( have_posts() ) :            the_post();            //your output per post in the first section//            //for example//            get_template_part( 'template-parts/post/content', get_post_format() );        //check for 'break' out of first loop//        if( $wp_query->current_post+1 == $posts_per_first_section ) break;         endwhile; ?><!-- closing html for first loop --><?php //checking if there are more posts to show in second loop        if( $wp_query->current_post > 0 && $wp_query->current_post+1 < $wp_query->found_posts ) : ?><!-- opening html for second loop --><?php while ( have_posts() ) :            the_post();            //your output per post in the second section//            //for example//            get_template_part( 'template-parts/post/content', get_post_format() );        endwhile; ?><!-- closing html for second loop --> <?php endif; //end checking if there are more posts to show in second loop    else :        echo 'no posts found';    endif;    ?>

Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>