• Jun
  • 07
  • 2012

How to assign different templates for post detail page of different categories?

Hello Friends !! Since a long time, I am working with wordpress and I got lot of challenges with wordpress customization.

Recently, I have a confusion that,

how can I make different single.php file for different posts?

After long research, I got a solution of this problem.

You can create as many single.php files as you want and you also can apply it to different posts. For example, In your site News section has a different layout then blog posts. At that time, this post will be very helpful to you .

Here I give you example that how you can do this.

First , create one file called single-categoryID.php in theme folder.

After creating this, go to single.php file which shows you full article.

After header, write below code:

if (in_category(’9′))
include (TEMPLATEPATH . ‘/single-9.php’);
elseif (in_category(’10′))
include (TEMPLATEPATH . ‘/single-10.php’);
rest of the code…….


Where ‘9’,’10’ is category id.

You can create as many templates as you want. You can also create multiple headers like this and include like asame above code.

Thats It !! Enjoy different template for different posts.

If you have any wordpress customization query or any confusion, feel free to ask me or comment me.

Ravi Makhija

Ravi Makhija

A writer, an Entrepreneur. Curious about the internet of everything. Interested in the cutting edge landscape of mobile apps and SAAS products. Blogs for Guru Technolabs - A Mobile App Development Company.

Let's Discuss a Project

Please share your unique idea or project requirement with us, our business concern person will get back to you with further details.