• Hi Guys,
    Is it possible to have 2 posts shown on the homepage (home.php) but then 10 posts shown on the next pagination page (www.example.com/page/2)?

    I’m using this in home.php currently:

    <?php if (!is_paged()) {
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $args=array(
                   'category_name'=>'topics',
                   'posts_per_page'=>2,
                   'paged'=>$paged,
                   );
                query_posts($args);
            } ?>
            <?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>
    // Do stuff
            <?php endwhile; ?>
            <?php endif; ?>

    And it works great on the homepage, but when I go to /page/2 it only displays the next 2 posts, rather than the 10 set in Reading Settings. I can’t figure out how to have 2 on the homepage, and 10 on the pagination page.

    Thanks for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here is some sample code that shows how to have a short first page:

    <?php $max_first_page = 3;  // Show this many posts on front page
          $args = $wp_query->query;
          $args['caller_get_posts'] = 1; // Using stickies messes up the count
          $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
          $posts_per_page = get_query_var('posts_per_page');
          $posts_to_skip = $posts_per_page - $max_first_page;
          if ($page == 1) {
             $max_posts = $max_first_page;
          } else {
             $max_posts = $posts_per_page;
             $args['offset'] = (($page - 1) * $max_posts)- $posts_to_skip;
          }
          query_posts($args);
          if ($wp_query->max_num_pages < ceil(($wp_query->found_posts + $posts_to_skip)/$posts_per_page))
            ++$wp_query->max_num_pages;
          $counter = 0;
          ?>
       <?php if (have_posts()) : ?>
          <?php while (have_posts()) : the_post(); ?>
             <?php if (++$counter > $max_posts) continue; ?>
                 // Rest of the loop

    Hi vtxyzzy,

    I want to achieve the same thing as you but I can’t get it to work with proper pagination. In your sample code wp_paginate(); doesn’t show any pagination… When I replace it with:

    <?php next_posts_link('Older Entries ?', 0); ?>
    <?php previous_posts_link('? Newer Entries', 0); ?>

    The second page doesn’t show the ‘Older Entries’ link while there are more entries. Any ideas on that?

    My code: https://pastebin.com/SHqS7nFZ

    See my topic: change-posts_per_page-inside-loop

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Different post amounts shown per pagination page?’ is closed to new replies.