Multiple Loops Homepage?

You can use current_post within the loop to track where you are and split the loop into multiple parts:

while ( have_posts() ) :
    the_post();

    // only output content if it's post 1 - 5
    if( 5 > $wp_query->current_post ):
        the_title();
    else :
        break;
    endif;

endwhile;

// do another query/loop
$custom_loop = new WP_Query( $args );
while( $custom_loop->have_posts() ) :
    // etc..
// snip....


// output posts 6 + of main query
while ( have_posts() ) :
    the_post();

    the_title();

endwhile;

You can also use $wp_query->rewind_posts(); to run the same loop again, or set current_post directly to start a loop at a specific post:

// start a loop at post 6
$wp_query->current_post = 5
while ( have_posts() ) :
    the_post();
    // etc..

Just remember that current_post is zero-indexed, it starts at zero, not 1.

Leave a Comment