WordPress: Multiple Single.php Template Files

WordPress Graphic for Multiple Single.php Template Files

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:

  1. Create two new template files based on the single.php template.
    • Example:  single-blog.php AND single.unique.php
  2. 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.
  3. 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!