How Do You Show All Posts In A Category On WordPress?
Apr 27th, 2007 by Greg Bulmash
It's a common frustration for people running WordPress. You set the number of posts displayed per page in the "Options|Reading" tab with the "Show At Most" option, and it uses that number both for your front page and for all the archive pages (category archive, monthly archive, etc.). So if you're showing four posts on the front page, and you've got 60 posts in a category, the category archive has 15 pages, and you want one page (maybe for easier navigation, maybe for SEO reasons).
How do you fix that? I'll tell you.
When trying to figure it out, I went to Google, and most of the instructions I found had to do with setting that number really high, then artificially terminating the loop count on the front page to limit it to 3 or 4 or whatever number you wanted. This works, but it requires multiple lines of code in multiple places and is easy to get wrong, breaking your front page.
I found something simpler.
The trick is that the query that tells your archive page to use the default you set on "Options|Reading" can be overridden with a single line of code. It takes four steps:
- Find your archive page template.
- Insert one line of code.
- Edit one line of code.
- Save your archive page template.
Step 1: Find Your Archive Page Template
On later versions of WordPress, in the administration section, you're going to want to click the "Presentation" option, then click "Theme Editor" in the sub-options. This will allow you to edit your current theme in your browser without having to bother with all sorts of FTP'ing up and down. Here's what it looks like when I do it.

Once you're in there, your job is to find the file that controls your archive pages. I use the Misty Look 2.3 template and it has two pages named "Archives".
How did I find out which one was the one? Simple... All of these templates are HTML, not PHP. They have PHP inserted between tags that look like <?php ... ?>. Anything outside of those tags will be plain old HTML. So after the first or second one of those <?php ... ?> bits, drop in a piece of text that says something like "this is the first archive page". Then click the "update file" button.
Now go look at the category page on your site. Do a fresh load or reload to make sure it's using the latest version of everything. Does it have that text? If it does, you've likely found the archive page. If not... go back to the "Theme Editor" page, remove that bit of text, update the file, and then try a different file. That's how I found out which of my two "Archives" pages was the one to edit.
Found it? Cool, you have completed the hardest part of the whole process. The rest should be easy.
Step 2: Insert One Line Of Code
So, here's how it works. In general, with later versions of WordPress, your archive page template will begin with...
<?php get_header();?>
Right after that, you're going to insert...
<?php if(is_archive) query_posts($query_string . "&posts_per_page=500"); ?>
First you have the "if(is_archive)" bit. That's important. If this template is controling other pages that aren't archive pages, you don't want to mess them up. So this instruction will only execute when WordPress knows it's displaying an archive of posts.
Second, if you have a category with more than 500 posts, you might want to increase that 500 to a higher number. But for most people, it should do the trick. If you have less than 500 posts in the category, it'll just show as many as you have. And now... you're done with Step 2.
Step 3: Edit One Line Of Code
If we ended with Step 2, we'd be okay, but we'd have a link at the bottom of the page that says "Next" or "More", but leads to an error message because there are no more posts in the category. If you're cool with that being there, skip to step 4.
You didn't skip to step 4, so I'm assuming you don't want that link. It's relatively easy to remove. Down near the bottom of the template, you'll find a PHP insert that looks like
<?php posts_nav_link(....) ?>. Whatever's between those parentheses can vary depending on how the theme designer wants the link to look. Change it to: <?php if(!is_archive) posts_nav_link(....) ?>.
Yup, all you're doing is adding "if(!is_archive)" between "php" and "posts_nav_link". Again, in case this template handles more than archive pages, you may want that link there in some cases. This tells WordPress to only execute the code that inserts that "next" link if the content being shown isn't an archive.
Step three... done.
Step 4: Save Your Archive Page Template
Remember in Step 1, when we were checking pages to make sure which one controlled the archive page? And remember how you'd click the "update file" button to save a change you'd made?
Click it.
You're done.
And That's It
When you view your category pages, you should now have all the posts for that category displaying, but your front page should only be showing the number of posts you set in that "Show At Most" option. Voila.
One small caution... if you change themes, you'll have to do this again in the new theme. So, just in case, bookmark this post.
Thanks - I'm working on my new site (which isn't up yet) and this was v.helpful!
Hi there,
Not sure if its even possible but I want this scenario but instead of just the home page showing a few posts. I want each category post to show say just 5 most recent posts and then the next page (e.g page 2) be an archive of all posts in the category. Is this possible?
@Saffron,
It's VERY possible, but would require about 2 hours to figure out and test. Just don't have time for that right now. Sorry. I'll keep it in mind for a future blog post.