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 🙂
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 aninclude
statement. single-.php would thus only output headers etc if no option was specified, else it would useget_template_part()
orinclude
to load the correct templateHow 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.
Why not just setup custom post templates so they can choose anyway?