How do I show 10 posts on the first page of the archive, and 20 on others (>1)?
My custom post type name is "apartments".
Cheers!
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityYou can change the posts_per_page
variable depending on the page you are on, so make it 10 on the first page and 20 on the other pages. However, you will have to modify the offset
query variable too, otherwise you will skip posts 11-20 on the second page, because this page thinks they are already displayed on the first page.
add_action( 'pre_get_posts', 'wpse15087_pre_get_posts' );
function wpse15087_pre_get_posts( &$wp_query )
{
if ( $wp_query->is_post_type_archive( 'apartments' ) ) {
if ( ! $wp_query->is_paged() ) {
$wp_query->set( 'posts_per_page', 10 );
} else {
$wp_query->set( 'posts_per_page', 20 );
$wp_query->set( 'offset', ( ( $wp_query->get( 'paged' ) - 2 ) * 20 ) + 10 );
}
}
}