How to change the number of posts on WordPress archive pages

We looked before at how to change the default number of posts displayed for your WordPress blog. The problem with the default is that - well - it's the default, and it applies to the home page, search results pages and archive pages equally (in most themes, anyway). What if you want a different number of posts on your archive pages to your home page?

To deviate from the default, all you need to add is one line of code:
<? query_posts('showposts=3'); ?>
Add this to archives.php to change the number of posts in category, date and author archives; to search.php to change search results' pages, or to index.php for the front page (as ever, this holds true for the majority of themes, but not absolutely all). The line needs to go *before* the loop <? if ( have_posts() )... etc. Change the number to whatever number of posts you want.

Plugin Compatibility

One small caveat: I've had problems using this with some of the pagination plugins that give you nice 1,2,3 etc. links rather than the standard "older/newer posts" links. There's probably a simple tweak... I just haven't had chance to find it yet.

Share this post:
  • email
  • del.icio.us
  • Facebook
  • FriendFeed
  • LinkedIn
  • StumbleUpon
  • Tumblr
  • Twitter

Tags:

Posted by Sue on June 17, 2009 in Themes, WordPress.

One comment to "How to change the number of posts on WordPress archive pages"

  1. Techawave wrote:

    Thank you, that was exactly the code I was looking for and couldn't find anywhere else!

Leave a Reply