0

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!

1 Answer 1

3

You 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 );
        }
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.