Not as easily, no. The reason for this is:
-Single posts can belong to multiple categories, so which category template should it use?
-Archive pages can have multiple posts, so again, which category template should it use?
That said, it would be possible to roll your own code to deal with this sort of thing.
All templates get run through a filter. In your case, the filters you’re interested in are single_template and archive_template. You could do something like this:
function choose_single_template($template)
{
// $template contains the filename of the template being used (like "/single.php")
// decide what template you want to use
$template = "/single-whatever.php";
// send it back
return $template;
}
add_filter('single_template','choose_single_template');
Basically, the filter gets the filename of the template. You can change it and return it and thus force a different template. You would probably want to put this sort of code in your theme’s functions.php file.
For the single:
http://guff.szub.net/2005/07/21/post-templates-by-category/
With the monthly archives is more complicated because WP doesn’t filter posts by month AND category.
Thanks!
I believe this is what I’m looking for, there will be only one category per post.
Now I just need to wrap my brain around it –
this filter would be declared in template-loader.php?
How would I pass the category? Maybe something like this:
} else if ( is_single() && $template = get_single_template($mcat) ) {
if ( is_attachment() )
add_filter('the_content', 'prepend_attachment');
include($template);
exit; }
function get_single_template($catid) {
$template = TEMPLATEPATH . '/single-'$catid.php;
return $template;
}
Thanks, blepoxp – I thought about using one big giant conditional for each of the pages (it’s my backup solution).
moshu – I’ll have to take a look at that and digest it a bit, thanks!.
That’s a plugin, you don’t have to “digest” anything – just install it and your single posts will work with the category templates.
There is also another plugin mentioned on that page: the
“inheritor” 🙂
Yep, already working! 🙂 I’ll check out the inheritor – thanks!!
No, Inheritor doesn’t help at all. I’m just going to pass the cat id via the url string and do some conditional statements.
Thanks everyone!
Hey, that Plugin works perfectly here, thanks Moshu
One question I have, how would you change the title on the category template so it would change when you are in the archive section to “Archives” or something like that?