I recently ran into an issue on a WordPress project that required multiple variations of the “single.php” template file based on a blog category. Unfortunately, there isn’t any built in support for multiple “single.php” template files like there are for categories. As a result, the quickest workaround is to convert your “single.php” into a PHP If Statement.
Here’s the breakdown:
- Create two new template files based on the single.php template.
- Example: single-blog.php AND single.unique.php
- Copy the contents of your single.php file to your two new template files.
- Customize the code of a template file to make it unique from the other.
- Replace the contents of your single.php file with this PHP If Statement:
Find your Category ID Number:
You can find the category ID number by navigating to your ‘categories’ manager in WordPress. From there hover over the category name and look at the link. It should have an ID associated with that category.
Hit me up in the comments if you need help. Cheers!
Aug 29, 2013
mohsin
this code is not working ….
can guide me plz…
Jan 20, 2014
Katia
Hello!
You just saved me. Thanks a lot 😀