title: Wordpress: Limit posts per page in category
body: <p>In my index.php I use this code to limit the posts per page and it works without any problems:</p>
  
  <pre><code>$showposts = 5;
  $do_not_show_stickies = 1;
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $args = array('category__in' =&gt; $cat, 'showposts' =&gt; $showposts, 'ignore_sticky_posts' =&gt; 1, 'paged' =&gt; $paged);
  
  $loop2query = new WP_Query($args);
  
  query_posts($args); if(have_posts()) : while (have_posts()) : the_post(); ?&gt;
  
  &lt;div class="blogpost"&gt; ... &lt;/div&gt;
  
  &lt;?php endwhile; endif;
  posts_nav_link(); // Navigating the pages with $showposts each. ?&gt;
  </code></pre>
  
  <p>The same code did not work in category.php so I changed it to the following but it still does not work:</p>
  
  <pre><code>$showposts = 4;
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  
  if (have_posts()) { while (have_posts()) { the_post(); ?&gt;
      &lt;div class="blogpost"&gt; ... &lt;/div&gt;
  
  &lt;?php } }
  
  else { ?&gt;
      &lt;p&gt;There are no blog posts in this category.&lt;/p&gt;
  &lt;?php } ?&gt;
  
  &lt;?php posts_nav_link(); // Navigating the pages with $showposts each. ?&gt;
  </code></pre>
  
  <p>I tried to change the line with <code>if(have_posts()) : while (have_posts()) : the_post(); ?&gt; [...]</code> in category.php to make it similar to that line in index.php but nothing I tried worked. </p>