Nerd tech, entertainment, and web development blog

WordPress Hacks: Separate Templates for Each Category

Sometimes, for whatever reason, we need separate templates for a specific category. Of course, you can always go with the built-in WordPress function to select specific categories, but after so many ifs and elseifs it might get a bit complicating and depending on how many changes you make, it might be more ideal to create a separate file anyway.

WordPress

So we have this category, lets say it is about technology and we want to change it by putting a different image and a slightly change the way to place the author links. The easiest way to make the changes is by creating a category specific page.

WordPress has a hierarchy of pages it looks at to determine which one to use. For category templates it is:


category-id.php
category.php
archive.php
index.php

This means WordPress first looks at the category-id.php page. If it is there, use that. If not, check for the category.php page. If it isn’t there, the archive.php, then the index.php.

So all we have to do is create a file titled ‘category-id.php’. Just change ‘id’ to the id of the category (don’t know your category ID? Go to wp-admin/Manage/Categories then hover your cursor over the category name. The number directly after the cat_ID= is your category ID.

In my case, the technology ID is 14. Since I am only making minor changes, I go to my theme folder, copy my category.php page and rename it to category-14.php

After a few changes, I’m all done. I edited everything I needed to and the page is unique from the other categories.

Written: Oct 16, 2008


Related posts »

2 Responses to "WordPress Hacks: Separate Templates for Each Category"

  • fragileheart
    October 16, 2008 @ 10:54 pm


    Wow that’s pretty neat. Especially for something like my Flickr Friday posts!

  • Dennis Edell
    October 17, 2008 @ 1:42 am


    I can’t see a reason for myself, but definitely for some. Nice one here :)