Show a custom template for a single post in a particular category

Add this filter to your functions.php and name your template file to match the category slug: single-[cat slug].php. If you’re using a child theme, replace TEMPLATEPATH with STYLESHEETPATH :
//Gets post cat slug and looks for single-[cat slug].php and applies it
add_filter('single_template', create_function(
'foreach( (array) get_the_category() as $cat ) {
if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") )
return TEMPLATEPATH . "/single-{$cat->slug}.php"; }
return $the_template;' )


This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s