Different number of posts on the front page

I want 5 posts on my front page but 10 posts on subsequent pages (page 2, 3, ..).

In my Settings > Reading > Blog pages show at most > I have 10. But I want to show only 5 posts on the front page, so in index.php I use this :

Read More
if ( $paged <= 1 ) $posts = query_posts($query_string.'&posts_per_page=5&paged='.$paged);

Works fine except that.. In page 2, the 6th to 10th posts don’t show. As if, from page 2, WP « thought » that the front page has actually displayed the 10 first posts, not just 5.

What can I do ?

Related posts

Leave a Reply

4 comments

  1. There is a post_limits hook that you can use for this purpose exactly:

    // in homepage show 6 posts
    add_filter('post_limits', 'homepage_limits' );
    function homepage_limits( $limits )
    {
         if(is_home() ) {
            return  'LIMIT 0, 6';;
         }
     return $limits;
    }
    
  2. Try this:

    $page_num = $paged;
    if ($pagenum='') $pagenum = 1;
    if ($pagenum > 1) { $post_num = 10 } else { $post_num = 5 }
      query_posts('showposts='.$post_num.'&paged='.$page_num); 
        if (have_posts()) : while (have_posts()) : the_post();
        endwhile;endif;
    
  3. Sorry, just got bored and am trawling through the archives. You could go with this:

    if(is_home() || is_front_page) { //some themes forget one or the other
        $post_num = 5;
    } else {
       $post_num = 10;
    }
    query_posts('showposts='.$post_num.'&paged='.$page_num); 
        if (have_posts()) : while (have_posts()) : the_post();
        endwhile;endif;
    
  4. Try this.

    function frontpage_custom_post_count(&$query)
    {
        // show specific number of posts on frontpage
        $frontpagePostsCount = 5;
        if (is_front_page() and !is_paged()) {
            $query->query_vars['posts_per_page'] = $frontpagePostsCount;
        }
        // show configured posts on the rest of pages, offsetting the ones showed on frontpage
        if (is_front_page() and is_paged()) {
            $posts_per_page = isset($query->query_vars['posts_per_page']) ? $query->query_vars['posts_per_page'] : get_option('posts_per_page');
            $query->query_vars['offset'] = (($query->query_vars['paged'] - 2) * $posts_per_page) + $frontpagePostsCount;
        }
    }
    add_action('pre_get_posts', 'frontpage_custom_post_count');