Creating Separate Templates for Different Categories

by Kishore on April 17, 2009

I was working on a template customizing it according to my need. I wanted a different look for my posts for Pictures and Galleries. I wanted to show these pages without sidebar and some changes in the page width for these pages. Its very easy to avoid the sidebar, but the page width should also be different so I needed to do some work on this.

In the single.php or the index.php depending on the template.

 

<?php 
    $picpost = false;
    $galpost = false;
    foreach((get_the_category()) as $category) { 
        if($category->cat_ID==4) { 
            $picpost=true;        
        }
        else if($category->cat_ID==26) { 
            $galpost = true;
        }
    } 
    ?>
    <?php 
    if($picpost) {
        include(TEMPLATEPATH."/picture-post.php"); 
    }
    else if ($galpost){
        include(TEMPLATEPATH."/gallery-post.php"); 
    }
    else {
    ?>

This will check for the category and include the right template page.

template_image-w590-h500

The template shown above is the same template (Revolution Theme) which I am using on this page. I have used some images from different templates to create this template.

Possibly Interesting Posts

Wordpress MU 2.9.1.1 Upgrade Error : Yesterday I upgraded my Wordpress MU installation to version 2.9.1.1 which has some fixes that I had..[](0)
5 Hacks that Will Challenge Obama's Cyber-Security Plans : President Barack Obama has made cyber-security a priority since he took office in January. A month ..[](1)
Freshen Your Fridge with Citrus Peels and Salt [Food Hacks] : We all know about keeping a box of baking soda in the fridge, but the TipNut blog suggests a citru..[](1)
Rubina dad unhappy with govt home : AGE CORRESPONDENT Mumbai May 30: Slumdog Millionaire child-actor Rubina’s father Rafiq Quereshi ..[](0)
Rejected by Apple, Palm teams with Amazon : You know the foolish game of cat and mouse Palm has been playing with Apple? The one where Palm hack..[](1)

{ 2 trackbacks }

Creating Separate Templates for Different Categories « Kishore
April 17, 2009 at 6:10 pm
Creating Separate Templates for Different Categories « Kishore’s Bookmarks
April 17, 2009 at 6:10 pm

{ 1 comment… read it below or add one }

jobmaldives April 27, 2009 at 9:45 am

Very Interesting and very useful. Thanks for sharing

Reply

Leave a Comment

Previous post:

Next post: