Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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 );
        }
    }
}
share|improve this answer
    
nice answer, thanks Jan! –  ilovewordpress Apr 19 '11 at 11:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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