WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/26/2016 08:06:43 AM (3 years ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/theme.php

    r38813 r38951  
    103103 *
    104104 * @since 1.5.0
    105  *
    106  * @param WP_Post|null $post Optional. The post being edited, provided for context.
     105 * @since 4.7.0 Added the `$post_type` parameter.
     106 *
     107 * @param WP_Post|null $post      Optional. The post being edited, provided for context.
     108 * @param string       $post_type Optional. Post type to get the templates for. Default 'page'.
    107109 * @return array Key is the template name, value is the filename of the template
    108110 */
    109 function get_page_templates( $post = null ) {
    110     return array_flip( wp_get_theme()->get_page_templates( $post ) );
     111function get_page_templates( $post = null, $post_type = 'page' ) {
     112    return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
    111113}
    112114
Note: See TracChangeset for help on using the changeset viewer.