HOWTO write your own WordPress category and tag archive templates
On one of my other sites, I needed a different number of posts on the category and tag archive pages than I did on the main index page. While there are a few ways to do this, there’s only one way that also works with the *_nav_link(); functions (which rely on the posts-per-page configuration option found in the admin panel).
The method is simple, just re-run “the loop” query on the tag and category page, re-using the page query:
query_posts($query_string.'&showposts=-1');
if (have_posts()) {
while (have_posts()) {
the_post();
// show the post content or just the titles here
}
}
Notes:
- It’s possible to rewrite the entire query yourself, but reusing the existing one is far simpler for most uses
- The
$query_stringvariable is a global containing the tag/category page query -1means: show all posts that match the current query- You can also use “the loop” just to show the titles (or excerpts, or any other post metadata)
You can customize your category or tag archive pages by providing your own template files (category.php, and tag.php respectively). You can even provide specific templates for each tag or category (like category-3.php), which provides some cool possibilities. For more details on custom category pages, see the WordPress wiki pages on Category Templates and Tag Templates.
