Today I Learned About WordPress Category Templates

Written by Thom Allen

Topics: Technology

Today I learned about category templates in WordPress. There is a simple, yet rarely used feature, that allows you to display content based on a specific category. For example, if you have 10 categories, with ID’s 1-10, and you want to show your visitors something different for each of these 10 categories, you can create files with this naming convention:

category-1.php, category-2.php, and so on.

When the URL http://mydomain.com/category/coolcat is entered into the browsers address bar, and WordPress sees a category request made, it looks for a category-x.php file in the main template folder. If one exists, that will be used over the default template file. If a template file isn’t found for the requested category, the next file that WordPress looks for is category.php. This is another template default file that can be applied to all categories that don’t have their own template. If a category.php isn’t found, then the default template file is used.

One thing I discovered while trying to get category templates to work, I was entering http://mydomain.com/coolcat and expecting the category template to display. But as you may know, WordPress was trying to find a Page named “coolcat”. I struggled with this for a week, and after ripping out the small hair follicles on my head, it dawned on me I was entering the wrong URL. Remember, /category/ must precede the category name, or it just doesn’t work.

Here is a link to the WordPress Codex explaining category template.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

3 Comments For This Post I'd Love to Hear Yours!

  1. Jake Spurlock Says:

    Jeez, that makes that big if/then thing we made a few weeks ago look a lot simpler…

  2. Thom Allen Says:

    Yeah, it's a feature I over looked. But now I know. Will this make that feature for your site work better?

    As I was thinking further, you could just add the different sidebar index, like sidebar 1 and 2 for cat 1, sidebar 3 and 4 for cat 2, and so on.

  3. lisalyne Says:

    Yeah, i know Wp is amazing, and alwaya offering new features for us. Like me, i never stopped learning something new about WP.

Leave a Comment Here's Your Chance to Be Heard!

Comments will be sent to the moderation queue.

« Back to text comment