Force Category Template
About
WordPress allows you to specify a template for a specific category. This is done by making a template and naming it category-X.php where X is the numeric ID of the category. This template is only used when looking at the category view. Several people have told me that they would like individual entries to also use this template. That is, an entry in category 3 should use category-3.php when it is viewed directly. This plugin enables that behavior. Note that this template will now be used for both the category AND the single view of posts in that category, so you will have to use the is_category() and is_single() functions if you want further differentiation.
For example:
<?php if ( is_category() ) { ?>
This is the category view
<?php } ?>
<?php if ( is_single() ) { ?>
This is the individual post view
<?php } ?>
Download
Instructions
Download the plugin, and upload to your /wp-content/plugins/ directory. Activate it via WordPress’ admin panel. You’re done!
Versions
- Version 0.1 Initial release


[...] The force category template plugin should allow you to use those category templates on a per-post basis in your main index.php view. Basically, assign your posts to one category, and your wife’s posts to a different category. Create a Category_Template for each category, then use this plugin. [...]
I will, however, delete or annotate comments I deem to be from trolls. I only write what I would dare say in public, so yes, I am this tactless all the time. You can contact me on me [at] this domain. CreditsWordPressCustom Query StringJust One Category Force Category Template Spam KarmaHelen’s imagesRandom Image Txtswap
Does this plug-in work with wrodpress 2.0? I would like to upgrade, but I don’t want to risk the site not working due to heavy use of this plug-in.
Thanks! Nice work!
I would be very surprised if it didn’t work in WordPress 2.0, as the things it relies on haven’t changed that much (if at all). In any case, if it doesn’t work (which would surprise me), let me know, and I’ll fix it as fast as I can.
Great plug in mate!, I can for sure see a very good use for this in a future website I want to make. Many Thanks for it, btw, works fine in WP 2.0.1
Hi there,
With this plugin can I use it as a template to feed to as a ‘page’ template so it shows as http://www.domain.com/history for example?
Does that make sense?
Off topic: How do you do your ‘welcome back’ code above?
Thanks
Karl,
No, this plugin does not alter anything with the URIs. What you would have to do is make a special page template for the “history” page that would call in the category stuff you wanted.
Welcome back code just checks the comment cookie values to determine if the person has previously commented.
Mark,
Thanks for that. Off topic and delete if you wish, but how would I call just that 1 category?
By the way I like what you write
Karl
Thanks
Try query_posts()
Something like
query_posts('cat=5&showposts=10');would load up 10 posts from category 5, and you would display them using a normal WordPress “loop.”I have a WordPress blog that includes a ’sort of’ photolog. What I want to do is when someone clicks on the ‘photolog’ menu item in my header that it take them to a single “post page” of the latest item I posted in that category and then allows them to use “previous post” “next post” to navigate. At the moment it does all this but displays it as a single “category” item.
Sorry for the dumb question: Is this what your plug-in does?? If so, can you help me figure out how to do it. I’m a cut and paste sort of guy and understand diddly-squat about PHP.
Just a note to say that after much cutting and pasting I’ve sorted it.
Thanks!
[...] Force Category template [...]
Hmmm…I think this plugin does what I want… but not sure… and don’t understand implementation…Could I ask for a little more enlightenment?
Posts use their
category-X.phptemplate even when being viewed as a single post, whereXis the category number. Normally, it’d usesingle.phpwhen viewing single posts, no matter what category they’re in.Gotcha..So should I see a page template option for category after activation?…then I would just write a page titled category-whatever #…and when viewing that category it will use that template? ( I am not seeing a new template after activation ) I am also using K2 if that complicates things….
You have to create
category-X.php. Keep in mind that it will be used for single posts as well as the listing for category X… so you may have to useis_single();andis_category();functions if you want the template to look slightly different depending on what you’re currently showing.okay…I am still confused…..I create a page named category-x.php where X= the category # using the regular default template…… but then I have a page in my main menu which I don’t want……
please be specific!!!
Then remove the page from your main menu. You’re going to have to leave your URI in your comment or it’s going to be very hard for me to figure out what’s wrong.
[...] Einen Moment bitte, die angeforderte Seite wird geladen… [...]
[...] http://txfx.net/code/wordpress/force-category-template/ da hasse
__________________ *~*~* "Ladies and gentlemen, they say the show must go on, but they never say why." Kermit, der Frosch sternengarten WP 2.0.1 (noch)Theme Neuron (lokalisiert) * Fauna auf Deutsch Die Baustelle [...]
[...] [...]
This plugin saved my life.
Great plugin, thanks for making it!
Can you force the posts to use a particular category template if a post has been assigned to several categories.
(if I have two categories A and B and both are children of C, when you click on a single post I want to load this with a sidebar specific to whether it is in A or B. When I’ve tried this A loads in the correct template (using the A category template) while B loads into C’s template [I do need the C template to show a page which combines A and B, so unfortunately I can't just remove this template to make it work].
Thanks
Hi,
From what your description says, this will do exactly what I need - carry the category template design through to a single post in a category.
I uploaded and activated the plugin, but when I try to look at a post in a category that has a special template the page gets stuck in a while loop. I get these errors:
Warning: rawurlencode() expects parameter 1 to be string, array given in /home/leadershipprogram/www/wp-blog-header.php on line 171
Warning: extract() [function.extract]: First argument should be an array in /home/leadershipprogram/www/wp-blog-header.php on line 184
Any other post not in a category that has a category template works fine.
Any ideas?
thanks,
K
[...] das ist evtl. auch was: http://txfx.net/code/wordpress/force-category-template/ __________________ *~*~* "Ladies and gentlemen, they say the show must go on, but they never say why." Kermit, der Frosch Mein Blog:sternengarten Mein Wordpress:WP 2.0.3 Mein Theme:Fauna Beta5 die Vorschau: Spiegelland Die Wordpress-FAQ [...]
Is this still needed in Ronan or 2.1?
Yes. This isn’t something that’s going to change for WP core… it’s special functionality.
[...] Force Category Template [...]
I installed your enforce preference plugin and activated it. Since I gather your plugin takes its lead from the options page (not clear in your instructions) and since I wanted the www to appear, I changed the URI from http://radiotomate.com to http://www.radiotomate.com. Now, despite 4 browsers and every combination of URL’s known to man. I and 5000 listeners are locked out of my website, all RSS feeds are neutralized and I am out of business. How do I get into my website to remove your plugin. Do I have to go in via the FTP and, if I just delete it will it still remain locked. Please help me, I can’t sleep. Thank you ! Jock
Thank you!
http://symy.jp/?Ct_220745
Is there any way so that users can leave comments on category views as well? Seems Wordpress assigns them to posts only.
[...] Contact Form ][ Customizable Post Listings Custom Query String Drop Down Categories Flexible upload Force Category Template Post Image Witty Text [...]
Heavy plugin, IMHO.
Nice site.
It’s cool site.
In bokmarks.
Thanks for this plugin, googled a week to find it, have only one problem nothing is load after single post content, layout is ok, but under this line “php the_content()” nothing is loaded since sidebar that work again. In short what i loose is comments and info about the post and comment box.
ciao
giuseppe
say a post is in category-X and category-Y. when viewing that post from category-X, I presume it has category-X’s template. when viewing the same post from the root of the blog, does it still have category-X’s template?
in other words, will an individual post only ever use a single template, and your plugin just changes what that template it based on whether it’s in category-X or not?
I have visited your site 929-times
I could not find this site in the Search Engines index
[...] Visit [...]
thanks for this plugin do u have a demo
[...] Ref: http://codex.wordpress.org/Category_Templates and a plugin I’ve found helpful with this: http://txfx.net/code/wordpress/force-category-template/ Hope this helps ~Flynn_________________Come see the Black Vatican Comic. Updating 5 days a [...]
Well, after searching the entirety of Google for an answer to my problem, your plugin fixed it instantly. Man, I was up until 3am hunting for the answer - this morning I came in fresh, found your plugin and now my single.php shows the correct template for each category . . .
Thank you . . . I mean it
[...] êà÷íóë ñåáå ïëàãèí force-category-template , êà÷íóë îò ñþäà http://txfx.net/code/wordpress/force-category-template/×èòàë íà èíãëèøå íî íè÷î íå ïîíÿë, õîòü èíãëèø çíàþ íîðì.Ïîìîãèòå ÷òî òàì è ãäå ñîçäàâàòü íàäî è [...]
Hi,
Please answer me… does this plugin work with wordpress 2.3.2?
: WP plugin that lets you completely customize the order in which your posts appear. If chronological or alphabetical aren’t sufficient, this is a great tool. I used it on my work portfolio so I could control the order by significance.Force Category Template: WP plugin that allows you to create custom templates for each category. I used this to create separate headers for all my category-driven pages, including work, blog, and photos. Get Custom Field Values
[...] Your page is on StumbleUpon [...]
Can you help me to make separate template for post viewing? I don`t want this plugin too change look of single posts.. How can I do to to not modify it`s template?
I just want to modify categoryX template.
I use your code and I have commented before
Once again, accept my good wishes
I prefer to minimize the use of plugin to avoid making my site slow. So Im looking for the actual code instead of this plugin. Good work anyway, Keep up the good work
To force the single post display to pick up the category template of the parent category, if no specific category template exits, I modified the plugin as follows:
` foreach ( $categories as $category ) {
if ( file_exists(TEMPLATEPATH . “/category-” . $category->cat_ID . ‘.php’) ) {
include(TEMPLATEPATH . “/category-” . $category->cat_ID . ‘.php’);
exit; }
elseif ( file_exists(TEMPLATEPATH . “/category-” . $category->category_parent . ‘.php’) ) {
include(TEMPLATEPATH . “/category-” . $category->category_parent . ‘.php’);
exit; }
}`
After googling everywhere for a solution to this, finally found your plugin. This is a Godsend.
After spending a long time to bifurcate my site’s look and feel into 2 category templates, I was so disappointed to find out that single posts didn’t retain their category template. One would think that Wordpress post links within Archives would automatically call-up a specific category template if one had been setup. I’m not a big fan of plugins either . . . but this really solved the problem.
Thanks again, Mark. I just made a small donation.
Jim
thanks for this, i was just about to write one.
however, what of the case where a post belongs to multiple categories?
the question of where and how page template transforms should be decided - we can only say ‘it is decided in context’ or by use-case.
in all cases however we can retain the concept of ‘current category’ - logically we should have a ‘view post in categories…’ view selector on each post; to be complete, also an ‘edit post in category view’ for authors.
‘current category’ could be set up as a stack of nested ‘category_event’ loops.
this plug-in here might help http://www.ilfilosofo.com/blog/2005/10/27/highlight-current-category/
but i think we might really need something like a push_current_category, and pop_current_category to allow developer to effectively code-up the user experience.
anyone know of anything?
This plugin allows a forced category template when the single post is clicked. However, just realized I’m not getting the same wonderful result when I try to access the post from a TAG link.
Any suggestions on how to get it to function the same way using TAGS?
Thanks again,
Jim
Hi dood i have little problems , build simple blog for new car bla bla … all category on my site preset one seperation blog (wp-admin/settings/Prermalinks/ Custom Structure : /mark/%category%/%postname%.html and Category base: mark/ ) problem is a script no work on this , scipt lock ID for link line $post->ID (script work ok on classic wp permalink http://localhost/?cat=100 ) don’t work on this http://localhost/mark/ford
Best Wordpress plugin I’ve seen all year. Thanks a million, this does EXACTLY what I’ve been looking to do!!!