Use different single post templates based on category

Need your single post views to be totally different depending on what category the post is in? You can do this easily by creating special single post files for each category as needed, and then replace the code in your single.php file with the following:

 <?php
if (in_category('jobs')) {
     include(TEMPLATEPATH . '/single1.php');
} elseif (in_categorye('News')) {
    include(TEMPLATEPATH . '/single2.php');
} else {
     include(TEMPLATEPATH . '/single3.php');
}
?>

Obviously if you only have one special category you won’t need the “elseif” statement in the middle.
Check the conditional tags reference in the Codex if you need to control the single post template by something other than category such as tag, post number, etc.

One Response to “Use different single post templates based on category”

  1. Hi. Great post. My friends referred your blogs to me. It looks like everyone knows about it, just not me, until now. Definetely will read your other posts, too. Thank you for sharing with us.

Leave a Reply