WordPress 4.7 will introduce support for post type templates, an exciting new feature for theme and plugin developers. Page templates, which allow developers to specify a different layout or design for a page, are nearly as old as WordPress itself. For years developers have coveted that same functionality for other post types. In fact, a plugin that attempted to create this functionality (Custom Post Template), has more than 50,000 active installs, despite not having been updated for four years.
Post type templates follow a format similar to that of the existing custom page templates. The author can specify a template name as well as the post types where the template will be available as a dropdown in the page attributes metabox. The current implementation of post type templates can be used with any post type without having to register support for page-attributes. The metabox will be displayed if at least one template exists for a post type.
* Template Name: Foggy Memories
* Template Post Type: memory, event
The ticket for the feature, which was opened four years ago, includes many potential use cases. One developer was building a project involving landing pages that were set up as custom post types. He needed to have multiple templates for the landing pages but had to create a work around since post type templates were not yet available.
Another developer wanted to make a distinction between posts with guest contributors versus those coming from regular writers, such as displaying author boxes and avatars. Since this project was for a client, an implementation involving post templates would make it easy to assign the different designs via the dropdown in the post attributes metabox.
“By opening up the page template functionality to all post types, we continue to improve the template hierarchy’s flexibility,” WordPress core committer Pascal Birchler said in his commit message. This new feature opens up many new avenues of customization for theme developers who want to offer alternative layouts and designs for posts. It also makes it easy to include multiple designs (inside a theme) for specific custom post types that a theme will support.