pablocattaneo
5/22/2015 - 3:16 PM

If you want to create a custom template for WordPress Posts, which belong to a specific category for example you can’t just create single-ca

If you want to create a custom template for WordPress Posts, which belong to a specific category for example you can’t just create single-catname.php. The solution to this is also not complicated at all. You need to create a function and preferably save it in your theme’s functions.php file. Here’s how to create a custom post template for a specific category: more:http://stanhub.com/create-wordpress-single-template-for-a-specific-category-or-custom-post-type/

<?php
 
function get_custom_cat_template($single_template) {
     global $post;
 
       if ( in_category( 'category-name' )) {
          $single_template = dirname( __FILE__ ) . '/single-template.php';
     }
     return $single_template;
}
 
add_filter( "single_template", "get_custom_cat_template" ) ;
 
?>