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-includes/post.php

    r38925 r38951  
    6767            'edit_item' => __( 'Edit Media' ),
    6868            'view_item' => __( 'View Attachment Page' ),
     69            'attributes' => __( 'Attachment Attributes' ),
    6970        ),
    7071        'public' => true,
     
    13271328 * - `all_items` - Label to signify all items in a submenu link. Default is 'All Posts' / 'All Pages'.
    13281329 * - `archives` - Label for archives in nav menus. Default is 'Post Archives' / 'Page Archives'.
     1330 * - `attributes` - Label for the attributes meta box. Default is 'Post Attributes' / 'Page Attributes'.
    13291331 * - `insert_into_item` - Label for the media frame button. Default is 'Insert into post' / 'Insert into page'.
    13301332 * - `uploaded_to_this_item` - Label for the media frame filter. Default is 'Uploaded to this post' /
     
    13521354 *              `items_list_navigation`, and `items_list` labels.
    13531355 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
    1354  * @since 4.7.0 Added the `view_items` label.
     1356 * @since 4.7.0 Added the `view_items` and `attributes` labels.
    13551357 *
    13561358 * @access private
     
    13751377        'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ),
    13761378        'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
     1379        'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),
    13771380        'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
    13781381        'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),
     
    33943397    $post = get_post( $post_ID );
    33953398
    3396     if ( ! empty( $postarr['page_template'] ) && 'page' == $data['post_type'] ) {
     3399    if ( ! empty( $postarr['page_template'] ) ) {
    33973400        $post->page_template = $postarr['page_template'];
    33983401        $page_templates = wp_get_theme()->get_page_templates( $post );
Note: See TracChangeset for help on using the changeset viewer.