Show posts per page in wordpress templates

I have 2 loops, one for the sticky blog posts (they are limited to 3 per page) and one for the rest of the posts. I want to show the 3 sticky posts + 5 of the other posts per page. Displaying only 5 of the other posts per page doesn’t work. This is the loop for them:

    $loop2query = new WP_Query('ignore_sticky_posts=1'.'showposts=5'.'&paged='.$paged);

  // START 2ND LOOP.
  if ($loop2query->have_posts()) : while ($loop2query->have_posts()) : $loop2query->the_post();
  // Show all posts except the 3 posts in the 1st loop.
  if(in_array($post->ID, $do_not_duplicate)) continue; ?>

  <div class="blogpost">
    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <p>Written on <?php the_time('m/d/Y') ?>. Filed under <?php the_category(', '); ?>.</p>
  </div>

  <?php the_excerpt();
  endwhile; endif; // END 2ND LOOP. ?>

I think 'showposts=5'.'&paged='.$paged must be the correct way to limit the posts per page, but I am note sure if I have used in my query correctly.

Related posts

Leave a Reply

1 comment

  1. I use this code to limit my category and post numbers per page, try it:

    <?php
    $cat = 1;
    $showposts = 5; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
        'category__in' => $cat,
        'showposts' => $showposts,
        'caller_get_posts' => $do_not_show_stickies,
        'paged' => $paged
       );
    $my_query = new WP_Query($args); ?>
    <?php query_posts($args); if( have_posts() ) :?>
    <?php while ( have_posts() ) : the_post(); ?>
    
    <!-- put title and content tags here -->
    
    <?php endwhile;endif; ?>