• Jun
  • 07
  • 2012
blog-image

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:

<?php
if (in_category(’9′))
{
include (TEMPLATEPATH . ‘/single-9.php’);
}
elseif (in_category(’10′))
{
include (TEMPLATEPATH . ‘/single-10.php’);
}
else
{
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.

Popular Blogs

recent-blog-image

Among the many digital tools that are being used with…

recent-blog-image

This question is most searched question in google. It is…

recent-blog-image

When you are using WPML in wordpress at that time…

recent-blog-image

Method for linking pages that aren't in a Site Menu…

recent-blog-image

Manier times we come across requirement like fetching/getting content from…

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.