I took me a while to wrap my head around this, but finally, I made it work.
I will share my solution here in case someone else is looking to implement a similar layout:
<ul class="post preview grid grid--blog">
<?php $do_not_duplicate = 0 ?>
<?php if(!is_paged()): ?>
<?php $args = array(
'category_name' => 'featured',
'posts_per_page' => 1
);
$featured = new WP_Query( $args );
while ( $featured->have_posts() ) : $featured->the_post();
$do_not_duplicate = $post->ID; ?>
<li class="grid__item grid__item-featured"><?php get_template_part( 'entry' ); ?></li>
<?php endwhile;
endif;
wp_reset_query(); ?>
<?php
$featuredid = get_cat_ID( 'Featured' );
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
if(!is_paged()) {
$postsargs = array(
'posts_per_page' => 4,
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'cat' => - $featuredid,
'paged' => $paged
);
$allposts = new WP_Query( $postsargs );
} else {
$secondPageArgs = array(
'posts_per_page' => 6,
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'cat' => - $featuredid,
'paged' => $paged
);
$allposts = new WP_Query( $secondPageArgs );
}
if ( $allposts->have_posts() ) :
while ( $allposts->have_posts() ) : $allposts->the_post();
if( $post->ID == $do_not_duplicate ) continue; ?>
<li class="grid__item"><?php get_template_part( 'entry' ); ?></li>
<?php endwhile;
endif;
wp_reset_query(); ?>
</ul>
So $do_not_duplicate
makes sure that you don’t repeat the Featured post from the first query in the second query when listing all the other posts.
And then wrapping our second query $allposts
arguments in the IF statement to check on which page those posts are going to be displayed. If we are on the first blog page, 'posts_per_page' => 4
will be called, otherwise 'posts_per_page' => 6
will be called on all the other pages.
Hope it helps!