If you want to display single post page using different single post template, then wordpress in_category() function will help to create different single post template.
First thing you have to create different single post template like
single_portfolio.php single_news.php single_wordpress.php single_default.php //For default single post template for post other than above categories.
Above three files i create because i want to use different single post page template for my portfolio,news and wordpress category respectively.
You can simply create copy of your single.php file and rename it with new template and do the changes that you want for each category.
After that open your single.php file remove all code and add following code
<?php
$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');
}
?>









February 6th, 2010












brilliant!
Perfect! Great solution! Thanks for sharing.
This is an excellent tutorial otherwise but am looking for a different variant of it. I am looking for a template which we can use to enter input of a new blog based on a template selected from the ‘Single Post Template’ drop down. The selected template will include input to custom fields as well. I would appreciate if anybody around can help me out.
TIA
Yes it can be done using the custom field.
I tried, but it’s not working… Definitely I’m missing something… Kindly anyone help me ?
let me know what problem you are having
What a brilliant solution, which beg the question, would it work if you use category ID instead? So we can format the single php template like the category-xx.php > e.g.: single-xxx.php?
Yes there is no any specific reason for the .php files. i just used names to differentiate it.. you can use what ever names to the php files.. important thing is the in_category(‘category_namge’)
you have to pass that category name.. and include respective php file.