Limit number of posts with Wordpress
I was looking for a way to limit the number of posts that came up on some page (doesn’t matter what: home, archive,…) and found this page by Justing Blanton. Justin notes that there is a way to do this in the admin section of Wordpress. But we like to do this on a particular page, not all pages. Now I don’t doubt his solution works. I just knew I had done this already differently on one of my sites, but I was too lazy to open up the folder on my computer that contained the file. The browser window was open so I typed a few words hoping to find the answer faster than opening the files of that site. That’s how I found Justin’s solution.
The solution I used was a bit different though, so I’ll post it here for those interested (yes I did have to look it up in my site folder in the end). You probably know the loop. If not, here’s the link to the codex page explaining it. What I did was just put something like this in front of it:
<?php query_posts(’showposts=7′); ?>
Put this in front of the start of the loop (in front of if ( have_posts() ) ), and the number of posts will be limited to seven. You can adjust the result a bit if you want to vary the number of posts depending on where you are. For example, if you like to limit the number of posts only on the frontpage, you might change this to:
<?php if (is_home()) { query_posts(’showposts=7′); } ?>
For a further explanation of query_posts, I will point you to the relevant codex page.