Wordpress Plugin: Category Templates

NOTICE: Support for this plugin has been stopped indefinitely. I simply don’t have the time to devote to working on updates and bug fixes.

If you’re interested in adopting this plugin to continue development/support, contact me.

Category Templates is a Wordpress plugin that lets you define different templates for both categories and individual posts through an easy to use interface.

I got the idea for this plugin when creating my own website with Wordpress. I wanted to be able to have different looks for my Portfolio, Projects, and Blog posts. I originally hard coded a few functions, but now I’ve created a simple and easy to use plugin that lets you define what templates to use for you categories and posts.

Due to multiple requests, 2.0 saw the addition of being able to apply templates to category archive pages as well as posts.

What does this plugin do?

When Wordpress is displaying a single post, it uses the template_redirect() function to determine the path of your theme’s single.php file. What this plugin does, is adds a filter to that function, and depending on your settings, chooses the appropriate template file based on the post. If the post or its categories don’t have a template defined, then template_redirect() falls back to its default (usually the single.php file in your template directory).

Category Templates also has a small footprint in the Wordpress database. All data is stored within two rows of your options table. I plan add the ability to delete these rows for when/if you want to uninstall in the next version.

Templates

Valid templates are files within your theme’s directory (/wp-content/themes/{your theme}/) with the following code in them (usually at the beginning):

For Post Templates:

1
2
3
4
5
<?php
/*
Template Name: Blog Template
*/ 
?>

And for Archive Templates:

1
2
3
4
5
<?php
/*
Archive Template: Blog Template
*/ 
?>

You can place them anywhere in your theme directory, even in sub-folders, as long as the above code is at the beginning of the file. If you recognize this method, then bravo (or brava – take your pick): this is the same way Wordpress uses to implement page templates (excluding the ability to place templates in sub-folders). When Wordpress loads all the files within your active theme directory, it searches for the ‘Template Name:’ string within a comment. If found, Wordpress declares that file as a template.

So to add a new template, simply upload the file anywhere in your active theme directory. Yup, it’s that easy.

If you’re not sure how to make a template for a post, I suggest taking a look at the single.php file in your theme’s directory. That is the default file that Wordpress calls when a single post is being displayed, and is a good starting point to go from.

Option Panels

Through the plugin’s options panel (located under the appearance tab), you can choose which templates are applied to categories, along with their priority level.

Options page for Category Templates

By checking the apply to sub-categories box for a category, all sub-categories of that category will have that template applied, with the defined priority. For instance, in the image above, the Projects category has a template with a medium priority, that is also applied to its sub-categories. However, the sub-category Music has a template with a high priority. Because Music’s priority is higher, that template will be used. However, if it was lower, then the Projects category would be used.

Post Meta BoxIf a post has multiple categories with the same priority, then the category with the lower ID will take priority.

When adding and editing posts, there is also a meta box for you to select a template for that specific post. However, please note that templates defined here will override any templates associated with the post’s categories, regardless of priority.

This is the first release of this plugin, so use at your discretion. And please let me know in the comments below any suggestions, comments, or bugs you come across.

Download

Category Templates 2.1

Download Stats

Today:  2
Yesterday:  8
This Week:  44
Total:  3,508

Version History

2.1

  • Added WPML Support (thanks Adrian)
  • Archive Template Support

2.0

  • Major Updates
  • Archive Template Support

1.0.4

  • Fixed Minor Bug

1.0.2

  • Added 2.7 compatibility

1.0

  • Initial Release

July 22nd, 2009 // Plugins

1 Star2 Stars3 Stars4 Stars5 Stars
(4.29/5) 7 votes.
Loading ... Loading ...

68 Responses to “Wordpress Plugin: Category Templates”

  1. The plugin is not working with version 2.9.1..any update ?

    Thanks for this wonderful pluting

  2. Fantastic plugin!!

    I found that it conflicted with the Custom Post Templates plugin I was already using, but fortunately you have that same functionality built in to this plugin. I’m sorry to hear you won’t be supporting it anymore, but hopefully the community will keep posting fixes as WordPress progresses. Great work, and thank you.

  3. I got the following message/warnings after upgrading to WP 2.9 RC1 Anybody have any tips on fixing this? Please..
    Thanks much!
    Warning: file(C:\wamp\www\wordpress/wp-contentC:\wamp\www\wordpress/wp-content/themes/black-hat/404.php) [function.file]: failed to open stream: Invalid argument in C:\wamp\www\wordpress\wp-content\plugins\category-templates\cat-templates.php on line 153

    Warning: implode() [function.implode]: Invalid arguments passed in C:\wamp\www\wordpress\wp-content\plugins\category-templates\cat-templates.php on line 153

  4. everything loads perfectly wp tables are made, but it doesn’t work

    I have the feeling its not working with child themes. I’m using hybrid theme and the news child theme. I i place them in the child folder they are recognized and also the main theme folder. but it doesn’t work proparly. One funny thing. it worked once or twice.. but now not anymore…

  5. wordpress 2.9 error , wish fix the problem

  6. Great plugin, is it possible to have templates for tags?

  7. HI, i installed this plugin but on admin side in category templates there is only menu, nothing else. Someone else posted similar problem. Any idea? Thanks

  8. Hi, I’m using this plugin and am having a problem.

    When I tried to use “get_the_category()” in a single post page, it returned no value. When I used this plugin for category archive pages, I had a similar trouble that the variable “$cat” returned nothing.

    Now I’m using “Idealien Category Enhancements” plugin to manage templates for category archive and I never experienced such problem.(WP 2.8.4) Do you have any ideas to fix the problem?

    Thanks!

  9. Thanks for this wonderful plugin. The current version (2.1) creates some bugs in my template – the videos and custom fields dissapear. Is there a way that we can download the previous version (1.04)?

    Thanks in advance

  10. Thank you very much for this wonderful plugin, especially now with version 2 !!
    If you want to make it compatible with WPML just need to add the following line after “cat_temp_options_page” opening:
    $_GET['lang'] = ‘all’;

    That’s all, it will show the categories in all the languages defined.
    Thanks again.
    Adrián

  11. Just checking in to see if there was any headway on the new version.

  12. Hey there – either we found a bug or … well, we really don’t know!

    We’ve installed the category plugin and it appears to work – we can choose which template goes to which page in the admin … however, it just doesn’t work on the front end. We’ve got custom templates running on the site and other plug ins of course but since the plug in appears to work in the admin we’re thinking it’s not a conflict. Does the plug in require anything special in the templates? We’ve added the required code at the top of the pages. We purposely took out a lot of the default WP side bar junk .. would that have anything to do with it? We’re at a total loss here and really need to find a solution. Any insight would be appreciated. Thanks

  13. Thank you so much, now I finally understand how it works! Great!

  14. Hello,

    I installed the plugin on my blog but all the options it gives me in the admin panel are the WP Default template and the template that I currently use, no matter which template I choose of the 5 I totally have. I have PHP 5.

    I added the code on the single.php of each template, the way you indicated. It still didn’t work. Then, thinking that the Default shows up no matter what, on the list, to change the code, exactly like on that one.

    To my recollection, this was the first plugin I installed so I don’t know if it involves a conflict with anything.

    I am not a .php expert, so I must have done something wrong myself but after a whole week of trying, I still cannot figure out what is going on.

    Can you please, help me with this?

    • I may just be misunderstanding you, but do you mean that you have 5 themes, and you added the code to the single.php page in each?

      If so, this plugin only works with your currently active theme, so only the pages in your currently active theme (and with the template code) will show up on the admin page.

    • Thank you so much for your quick reply. I think I finally understand… but to make sure I do, I have a few more questions:

      1) I should actually have a folder/subfolder structure, like:
      themes / Blue_Theme / orange_theme
      _____________________ / white_theme
      _____________________ / pink_theme
      _____________________ / green_theme
      with a single.php containing that little piece of code at the beginning, in each subfolder?

      2) Will this change the appearance completely, for each category, I mean from layout to images (background, header, buttons, etc.)? – That’s what I want to happen!!!

      2) Do I also need to add the code at the top of other .php files like page.php, index.php, etc. on each sub-theme or not?

      Thanks again!

  15. Did you have any luck getting templates to apply to the archives pages?
    I keep checking back each day but have not seen any new comments or posts about this yet. I’m still very interested!

  16. Applying templates to the category archive pages is exactly the feature I have been searching for. Is there an e.t.a. on when this feature may be added?

    My idea is simple: Create a multimedia website where artists can upload their own audio/video files. I would create multilevel categories such as:

    Artists
    –Artist
    —Album
    —-Song/Video Article

    If I had the ability to assign custom templates to categories, then I could easily make the ‘artists’ top level listing look totally different than the ‘artist’ or ‘album’ listing pages.

    Really the only hack I would have to implement is to hide ’sub-categories’ from showing up on category listing pages.

    That would open up some huge doors with Wordpress.

  17. Awesome plugin, but I’d like to see custom templates for the post archives. I downloaded this plugin because I thought that’s what it was for. Can’t wait for the next version to have that feature!

  18. Hello, nice plugin. It works fine for posts templates, but I’m trying to make it work for categories and it doesn’t seem to work. I asigned the plugin at Settings for Category Templates and it takes the post template, not the category template. Can you help me please?

  19. Hi there;

    Same problem here – loaded the plugin, checked that all templates have therequired commented-text in them, and when I go to the Category Templates area of the appearance tab, I get everything in the screenshot you’ve shown, but only up to the bottom of the horizontal grey bar… that is, no caegories whatsoever are listed.

    I’m going to uninstall and re-install and see how I go. Disabling other plugins isn’t an option – the yall have to be able to live together.

    Cheers

    GT

  20. Great Idea and potentially what it can do, thanks.

    However, I have an issue. The plugin enabled, Templates Shows up for selection. However No post shows up, post page is blank after plugin is enabled.

    I have disabled all plugins, and am using the Hybrid Theme from themehybrid.com.

  21. Great plugin! I’m excited to get to it!

    One (hopefully quick) issue — after activating, I am unable to edit existing posts or view the plugin settings. both return the following error:

    Fatal error: Call to undefined function: str_ireplace() in /wordpress/wp-content/plugins/category-templates/cat-templates.php on line 155

    Any idea what i should be fixing?

  22. Hello,

    Great plugin! However, I’ve added the code to my template file, and only “No Template” and “Default Template” appear in the list.
    What am I’m doing wrong?

    I’m using Wordpress 2.8.4

    • Here’s a few things to try:

      Make sure you added the code to your template file:

      <?php
      /*
      Template Name: Blog Template
      */
      ?>

      You can change Blog Template to whatever you’d like, but the important part is to keep Template Name: the same, as the plugin searches for that sting.

      Also, make sure you put the template file into your currently active theme folder (wp-content/themes/templatename/).

      Let me know if you’re still having issues.

      • I’ve check all those things, but my template is still not listed.

        I also have other problem I didn’t see before. All the links of my site are redirected to the home page when your plugin is enabled. When I disable the plugin, my posts are shown as usual.

        I’m using many other plugins and I think there is a compatibility problem with another plugin. I will try to find which plugin it is.

      • what this looks like is a way to use other WP themes on a certain page with all their functions, but you mention a singular template page to put the commented code at the top of.

        You also mention putting the template inside your active theme folder.

        So say my overall WP theme name is “Slider” there is a theme folder called slider in the WP-content/themes/

        Now adjacent to Slider is another complete theme for WP called “Bluebell”

        Are you saying that I need to put the complete Bluebell theme folder inside /Slider ?

  23. When I activated this plugin all URL’s where pointing to the latest post. I deactivated it and it is fine without the plugin.

  24. Thanks! Your plugin works perfect, but when PHP error messages are turned on, I get this:

    Warning: Invalid argument supplied for foreach() in /path/to/my/site/httpd.www/wp-content/plugins/category-templates/cat-templates.php on line 91

    Warning: Invalid argument supplied for foreach() in /path/to/my/sitehttpd.www/wp-content/plugins/category-templates/cat-templates.php on line 99

    See the URL: http://wordpress.org/support/topic/304680?replies=1

  25. Not sure you offer this.

    I’m looking for a plugin that takes category pages and displays them from this http://boxedindesign.com/category/inspirations/ to this http://boxedindesign.com/top-lists/. Everything I download seems to be too old, but yours is the newest I’ve seen and looks like what I need, but I’m not sure. Is your plugin what I need or is there one you could recommend? I’m no expert at WP so there is a learning curve.

    Thanks!

  26. Hi, in the dashboard on my 2.8.2 I find the Post Template option, but I can only choose between Default Template and Archieve Page. Have I misunderstood, I have built a variant of my theme, and hoped it could be assigned to posts in specific categories. But it doesnt work like that?

  27. I’ve installed the plugin and am having a problem too.
    I have the administration panel and selected my category template, but the plugin does not work. I’ve installed the Wordpress 2.8.2, but it still does not work.
    Sorry for my English

    • A few things for me to ask/you to try:

      • Try disabling all other plugin’s. See if there is any change.
      • When you say it doesn’t work, do you mean your posts aren’t displaying with the selected template?
      • Can you confirm that there is a row in your database’s wp_options table. The option_name for the row is cat_temp_data
  28. I’m just checking out this plugin, it looks very promising for a problem I’m trying to solve. Very promising.

    Before I’ve really used it at all, I noticed a typo in the first line:
    Plugin Name: Categorty Templates

    Thought you’d like to know!

  29. Can assign template to gallery, overriding the default category?

3 Pinback/Trackback's to “Wordpress Plugin: Category Templates”

Leave a Reply

Name:
Email:
Website:
Message:
SUBMIT