• Portfolio of •
Veronica Wong

WordPress: different number of posts per page

October 15, 2009

WordPress allows you to set the number of posts to display on each blog page, but it does not allow you to set a different number of posts between different blog pages. A recent job of mine required me to do so and I found a couple of ways to do it.


I first found the Different Posts Per Page plugin. Now, before I ever even think of installing a plugin, I read through the WordPress forums to see whether or not it would be suitable for me. Several users complained that the author of this particular plugin made them register their email address and say yes to a newsletter in order to use the plugin. I found this to be extremely annoying and didn’t even bother installing the plugin. I ended up doing a bit more reading and found that a simple line of code would solve my problem!

I simply had to run a query before the WordPress loop:

[php]<?php query_posts($query_string.’&posts_per_page=50′); ?>[/php]

The above query allowed me to show 50 posts on that specific blog page, while all the others maintained the default of 10 posts per page. If I wanted to show all posts, I would simply replace 50 with -1.

Comments

Thanks, I was determined to find a way around using that plugin for something as simple as this. I try to avoid plugins (especially small ones) as much as possible as I have the feeling they will just break after about 2 weeks lol.