Use Different Single Post Template Per Category in WordPress
Do you want to display single post using different single post template? WordPress has great template hierarchy in order to design a versatile blog or a business website. In this page, we are going to share a WordPress tip to use different single template per categorie. You may have different single page for a category ‘portfolio’ and a different single page for ‘news’ and so on. Here is a easy how to:
First thing you have to create different single post template like:
single_portfolio.php single_news.php single_wordpress.php single_default.php //default single post template
Then open your single.php file, remove all code and add following code:
$post = $wp_query->post;
if (in_category('portfolio')) {
include(TEMPLATEPATH.'/single_portfolio.php');
} elseif (in_category('news')) {
include(TEMPLATEPATH.'/single_news.php');
} elseif(in_category('wordpress')) {
include(TEMPLATEPATH.'/single_wordpress.php');
}
else{
include(TEMPLATEPATH.'/single_default.php');
}
Once you saved it and uploaded the file, posts are displayed on different pages differentiated by category.
