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.

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 :

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 ?

share|improve this question
    
You'll have to write your own code to deal with paging and query offsets in order to have different post per page values on the different pages, it's simply beyond the scope of what queries support in WordPress. I've at least answered similar questions before on the wordpress.org forums though, i'd suggest starting with a search there. –  Mark Duncan Jul 16 '11 at 12:35
    
Any plugin to do the trick ? –  Mike Jul 16 '11 at 21:57
add comment

5 Answers

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;
}
share|improve this answer
add comment

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;
share|improve this answer
add comment

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;
share|improve this answer
add comment

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');
share|improve this answer
1  
Please add an explanation to your answer: why could that solve the problem? –  toscho May 28 '13 at 22:21
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.