0

Create WordPress Single Template for a Specific Category

Create WordPress Single Template for a Specific Category is my project need so i have write the following code to do it in pretty way. Throughout the comments of the article were about 15 different versions of how to accomplish getting different single.php templates for different categories.  I went through them and combined them into what I feel is the best solution that keeps in tune with other WordPress naming conventions.

First add the function below to your theme functions.php

Second you need to duplicate your current single.php file and rename it to the following naming convention.
If the category slug is ‘photos’ then you use single-category-photos.php If the category slug is ‘hamburgers’ then you use single-category-hamburgers.php
You’re probably asking why the annoyingly long template name. Well there will be a time (or a plugin you install) that will have a custom post type as ‘photos’ or ‘hamburger’ and this will allow those custom post types to have the built-in ‘single-photos.php’ name.  That and it’s super easy to understand.

Enjoy.

Sandeep Kumar

Sandeep kumar is a web developer and a professinal blogger. He works for latest technologies and write articles what he learn. In ICodeHub he share web languages tutorials and other programming tips and tricks. if you need some help or have some suggestion then mail him at sandeep92pal@gmail.com without any hesitation. He believes in learning and sharing.