WP plugin: Post Templates by Category
Post Templates by Category (PTbC) is another WordPress plugin I’ve had stuck between couch cushions the last several months. The benefit of PTbC is that it lets you set custom templates for all posts within a category.
To install, here are the memorable steps: Download the zip file; extract post-templates-by-cat.php; upload this to your wp-content/plugins directory; and (finally!) activate Post Templates by Category under Plugins in WordPress.
The single variable — actually, it’s a PHP constant — you need to know about is
SZUB_TEMPLATENAME_PREFIX. Look in the plugin for this section:
/* >> Begin user-configurable variable >> */ define('SZUB_TEMPLATENAME_PREFIX', 'single-cat'); /* < < End user-configurable variable << */
The value for this informs PTbC of the filename, or rather the prefix used for your templates. The default shown above is
'single-cat'. So if you wanted to apply a template to all posts in category #10, you'd make sure to name the template
Let's say you set
A benefit of this is that it causes the template used for a specific category query (something built into WordPress since version 1.5) to be "annexed" by posts within that category. So a template for category #5 (
category-5.php) will also be applied to all posts in that category.
Whatever scheme you go with, just make sure to end each template with
-#.php, replacing # with the numeric category ID. Putting PTbC to use merely requires creating the template(s). And for help along those lines check out the WordPress Codex articles on Templates and Themes.
$template_namevariable with the
SZUB_TEMPLATENAME_PREFIXconstant. Information above was edited to reflect the change.