WordPress Custom Category Archives

Note, we’re talking here about different category archive pages – not having a post page customised according to the category that post is in….

There’s 2 ways of doing this – first, the simple way, for more minor changes to the overall theme template, you can use the is_category function:

if (is_category('featured')) {
// some different code here for the featured category archive
// such as, if this code is in the header, load a different or supplementary stylesheet
} else {
//code here for every other category - if required...
}

So for example, you could have a category set aside for video posts and have its archive page display extra information about each post, using get_post_meta()
And single_cat_title() has its uses in this context.

Custom Category Templates

But secondly, just like WordPress page templates, you can customise by category by using a separate template file.

All you need to do is copy say, category.php to a new file: category-video.php and make the desired changes. This way, WordPress will find and load this file for you, via its priority in the template hierarchy

The template hierarchy: WordPress works down the list, checking for a match – the first file found that satisfies the criteria is the one used to display the archives for that category.

1st. category-slug.php – define category using its slug name (WP 2.9+ only)
2nd. category-ID.php – define category using its ID
3rd. category.php
4th. archive.php
5th. index.php – the default template

(Note also, it’s a hypen not an underscore)

This does amount to roughly the same thing as a conditional php include, but can be a more elegant way of doing things…