Category Specific Single Post Templates

Sometimes we may required different category related single post template , i get the following things .
First put the code in function.php

// set up category specific single.php templates
add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-{$cat->slug}.php"; } return $t;' ));

Then create file as single-categoryname.php. Now the custom template will load while loading the page related to the categoryname.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.