Single post template based on category

Today, while trying to customize the single.php template for a specific category I found a pretty old article written by Lorelle:

Creating Multiple Single Posts for Different tags.

Her tip is really simple and really useful: just rename your single.php to single1.php and create a new single2.php with your category specific layout; after that, create a new single.php file with this code:

$post = $wp_query->post;
if ( in_category('1') ) {
  include(TEMPLATEPATH . '/single2.php');
} else {
  include(TEMPLATEPATH . '/single1.php');

So, if the post is in category 1 WordPress will use the single2.php otherwise it will use single1.php.


I wrote a more flexible solution: check it out.