Somebody over at WordPress has thought of just about everything.
The more I use WordPress and implement it into my web design projects the better I understand what a full featured Content Management System it really is. I recently wrote an article desscribing one of my favorite WordPress features which allows you to assign separate category template pages for different post categories. This article explains this concept in a bit more detail.
Most of the standard WordPress themes include a file name archive.php
. This file is called each time a user accesses an archived post. Examples of archived posts are:
- Monthly posts
- Yearly posts
- Post within a certain category
When a user views the selected archived posts, the page displayed by the browser is controlled by the archive.php
file and the XHTML code within that page. Often times this archive.php
file is customized to offer the user information about the subset of posts that they are viewing. For instance, if you view the archives on this website for the posts filed under the category “Blogging” you will notice that the first paragraph of the page offers you a brief advisory of just what posts you are viewing.
As you can see from this example, the overall template look and feel is the same as the rest of this site, with the exception of the opening paragraph. This archive.php
files displays the same format for any post that is part of the archive records.
Specialized Templates for Individual Categories
But what if you want the posts made under this category to be displayed on a page that has a completely different apperance than the rest of the blog? Sometimes this is a necessary part of a design project. WordPress has allowed you to customized the look and feel of individual category pages as well.
Follow these simple instructions to design a specialized category page for your blog:
- Enter the WordPress dashboard and choose Manage->Categories from the menu.
- Make note of the category ID number associated with the category you are interested in designing a template for. For the sake of this example, let us say that this is category #8
- Copy the
archive.php
file and save it as a new file - Name the new file
category-8.php
- You are finished!
WordPress Does the Rest
Based on the heirarchy of page structure in WordPress, anytime a viewer chooses to view the files located in category 8 they will be viewing the code displayed by the category-8.php
file rather than the more basic archive.php
file. You simply need to customize this file to display your posts in any manner that you desire.
Who Needs Category Templates?
On first glance you might not be able to think of any use for WordPress specialized category pages. When I first read about them a couple years ago I could not think of how category page templates would be use to me.
However, while working on a recent project I found that I needed to display a scrolling list of “Appearance Dates” for upcoming events. These dates were nothing more than short WordPress posts, but they needed to be displayed in an entirely different way than the other traditional blog posts. Something in the back of my mind told me that cetegory templates might be just what I need to use. Guess what? Using WordPress category template pages solved my problem. Maybe they can solve a problem for you someday, too!
[eof]