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.

$post = $wp_query->post;

if (in_category('1')) {
} elseif (in_category('2')) {
} else {

Your choice for site templates and wordpress themes


Got something to say?

You must be logged in to post a comment.