Well first of all, we can get rid of all the query_posts
business in the template. There’s always a better method than using query_posts
.
If the primary goal is to have 5 posts on the first page and 4 on all subsequent pages, we can do that very easily before the query happens via a function in the theme’s functions.php
hooked to the the pre_get_posts
action.
This basically says “If it’s the home page and the main query, check the page number- if it’s less than page 2, load 5 posts, otherwise load 4.”
function wpa_featured_posts_per_page( $query ){
if( $query->is_home() && $query->is_main_query() ){
if( 2 > $query->query_vars['paged'] ){
$query->set( 'posts_per_page', 5 );
} else {
$query->set( 'posts_per_page', 4 );
}
}
}
add_action( 'pre_get_posts', 'wpa_featured_posts_per_page' );
As for styling the first post differently, you can check the global $wp_query->current_post
within the loop and output different markup if it equals zero or greater than zero (current_post is zero-indexed, it starts at zero and goes up from there).
You can also run the same loop more than once by calling rewind_posts();
to reset the internal post counter.