WordPress – Different Post Templates Per Category

By: PowAxx | March 26, 2010 at 10:09 am | Posted in Web Design
Tags: , ,
About: Setting diffent templates on post in each category can be done in Wordpress by tweaking the template files and adding short PHP codes.

Define different post templates based on the category they belong. This is useful if you want each posts on different category to have different looks. To do this please follow this:

1. Copy single.php to single-default.php. Your default template will be single-default.php
2. On single.php file remove all contents and insert the this code.

<?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’);
}
?>

3. Copy single-default.php to single1.php (template for category number 1) and modify it based on your preferences. Repeat the process on each category templates.

Leave Comment