Use different single template per wordpress category
November 11, 2008 · Print This Article
Why a blog must always have the same layout? I’m going to tell you how you can define differents post layouts for each of your categories.
First, you’ll have to create each different layouts you’d like to use. They’re named single1.php and single2.php. The default posts template is single_default.php.
Once you have your templates ready, insert the following code on your regular single.php file. When single.php will be called, this code will automatically include your custom layout based on the current category id.
<?php
$post = $wp_query->post;
if (in_category('1')) {
include(TEMPLATEPATH.'/single1.php');
} elseif (in_category('2')) {
include(TEMPLATEPATH.'/single2.php');
} else {
include(TEMPLATEPATH.'/single_default.php');
}
?>





















Comments
Got something to say?
You must be logged in to post a comment.