Multiple templates for posts

singlepost

I was developing a site for a client who wanted to show the post in a different template depending on it’s category. We all know that you can easily have different templates for pages using the following code at the top of your page template:

<?php
/*
Template Name: The Template Name
*/
?>

But this doesn’t work for posts. However there is a way to do it, I give to you the ‘Single Post Template Plugin’. Much like when you select a template for a page when you create it, this plugin allows you do do the same for a post.

Similarly to a page template you have a small bit of PHP code at the top of you template that gives it it’s name:

<?php
/*
Single Post Template: The Template Name
Description: Optional
*/
?>

So to use this plugin do the following:

  1. Download and activate the plugin
  2. create your templates, adding the above code to the top of the template
  3. when creating the post select your template from the ‘Single Post Template’ box.

Thats it… You should now have different templates avalaible for your posts.

Hope this helps you out, please leave comments or questions.

Alex

1,689 views
Alex considers himself and expert in CSS. He has been working for the last 6 years as a senior developer for the NHS and the past 4 years as a freelancer specialising in Wordpress theme development, using jQuery for added awesomeness! Contact him via @ajthomascouk or ajthomas.co.uk.

Got something to say? Go for it!