Is it possible to set up templates for custom post types?

For example you have a portfolio page with 4 different variations of layout and you want the user to be able to pick which layout they want for this post/page?

Wondered if any of you good folk knew of a way?

Thanks :)


2 Answers 2


First ofcourse we have single-<posttype>.php but I don't think that's what you want ( yay if it is )

To implement this, you would need a metabox, with a dropdown that saves the value to a custom field, which you would then pull from in single-<posttype>.php and then use in an include statement. single-.php would thus only output headers etc if no option was specified, else it would use get_template_part() or include to load the correct template

How you populate that combobox/dropdown is up to you. You may have 5 preset templates and hardcode the filenames, or you may decide to put in code that checks each files header like Wordpress does with pages.

  • I usually use <?php echo get_post_meta($post->ID, 'meta-box-name',true); ?> to get my meta box info, how would i write an if statement to say if meta bot drop down 1 do this if 2 do this else etc...?
    – Jezthomp
    Nov 14, 2011 at 13:33
  • $value = get_post_meta($post->ID, 'meta-box-name',true); if($value == 1){ // do this... } else if($value == 2){ // etc..
    – Tom J Nowell
    Nov 14, 2011 at 14:35
  • Thanks Tom i'll give that a go, since your help i've found this also, do the same thing? wordpress.org/extend/plugins/custom-post-template
    – Jezthomp
    Nov 14, 2011 at 14:52
  • Almost, that does it for normal posts, not custom posts, at which point you should really be using custom post formats instead.
    – Tom J Nowell
    Nov 14, 2011 at 15:05

Why not just setup custom post templates so they can choose anyway?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.