RSS Amplifier

Andy Brudtkuhl · Sep 25, 2015

WordPress Single Page Template For Categories

0
Sign in to vote or save

Andy Brudtkuhl · brudtkuhl.com

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.


Read the original on brudtkuhl.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.