Posts, Post Types: Add support for post type templates.

WordPress has supported custom page templates for over 12 years, allowing developers to create various layouts for specific pages.
While this feature is very helpful, it has always been limited to the 'page' post type and not was not available to other post types.

By opening up the page template functionality to all post types, we continue to improve the template hierarchy's flexibility.

In addition to the `Template Name` file header, the post types supported by a template can be specified using `Template Post Type: post, foo, bar`.
When at least one template exists for a post type, the 'Post Attributes' meta box will be displayed in the back end, without the need to add post type support for `'page-attributes'`. 'Post Attributes' can be customized per post type using the `'attributes'` label when registering a post type.

Props johnbillion, Mte90, dipesh.kakadiya, swissspidy.
Fixes #18375.

git-svn-id: https://develop.svn.wordpress.org/trunk@38951 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2016-10-26 08:06:43 +00:00
parent ee14487043
commit a9516abb54
18 changed files with 391 additions and 150 deletions

View File

@@ -449,15 +449,17 @@ function get_search_template() {
*
* The hierarchy for this template looks like:
*
* 1. single-{post_type}-{post_name}.php
* 2. single-{post_type}.php
* 3. single.php
* 1. {Post Type Template}.php
* 2. single-{post_type}-{post_name}.php
* 3. single-{post_type}.php
* 4. single.php
*
* An example of this is:
*
* 1. single-post-hello-world.php
* 2. single-post.php
* 3. single.php
* 1. templates/full-width.php
* 2. single-post-hello-world.php
* 3. single-post.php
* 4. single.php
*
* The template hierarchy is filterable via the {@see 'single_template_hierarchy'} hook.
* The template path is filterable via the {@see 'single_template'} hook.
@@ -466,6 +468,7 @@ function get_search_template() {
* @since 4.4.0 `single-{post_type}-{post_name}.php` was added to the top of the template hierarchy.
* @since 4.7.0 The decoded form of `single-{post_type}-{post_name}.php` was added to the top of the
* template hierarchy when the post name contains multibyte characters.
* @since 4.7.0 {Post Type Template}.php was added to the top of the template hierarchy.
*
* @see get_query_template()
*
@@ -477,6 +480,10 @@ function get_single_template() {
$templates = array();
if ( ! empty( $object->post_type ) ) {
$template = get_page_template_slug( $object );
if ( $template && 0 === validate_file( $template ) ) {
$templates[] = $template;
}
$name_decoded = urldecode( $object->post_name );
if ( $name_decoded !== $object->post_name ) {