WordPress Single Page Template For Categories

September 25, 2015

wordpress

If you are familiar with building WordPress themes you've likely caught onto the naming convention used for page templates. These conventions are things like 'page-{slug}.php', 'single-{slug}.php', and 'category-{slug}.php'. The conventions are very handy and I wanted something similar for posts in a category. This method is much cleaner than having conditional logic all over your 'single.php' file to do have different design elements or functionality for posts in different categories. A simple one-liner to drop into your theme's functions file does the trick... Now, you can create 'single-news.php' for a post in the News category and 'single-blog.php' for a post in the Blog category and have completely different designs and layouts.

Subscribe to my mailing list