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/class-wp-posts-list-table.php

    r38854 r38951  
    15291529            </label>
    15301530
    1531     <?php   endif; // !$bulk
    1532 
    1533             if ( 'page' === $screen->post_type ) :
    1534     ?>
    1535 
    1536             <label>
    1537                 <span class="title"><?php _e( 'Template' ); ?></span>
    1538                 <select name="page_template">
    1539     <?php   if ( $bulk ) : ?>
    1540                     <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
    1541     <?php   endif; // $bulk ?>
    1542                     <?php
    1543                     /** This filter is documented in wp-admin/includes/meta-boxes.php */
    1544                     $default_title = apply_filters( 'default_page_template_title',  __( 'Default Template' ), 'quick-edit' );
    1545                     ?>
    1546                     <option value="default"><?php echo esc_html( $default_title ); ?></option>
    1547                     <?php page_template_dropdown() ?>
    1548                 </select>
    1549             </label>
    1550 
    15511531    <?php
    1552             endif; // page post_type
     1532            endif; // !$bulk
    15531533        endif; // page-attributes
    15541534    ?>
     1535
     1536    <?php if ( 0 < count( get_page_templates( null, $screen->post_type ) ) ) : ?>
     1537        <label>
     1538            <span class="title"><?php _e( 'Template' ); ?></span>
     1539            <select name="page_template">
     1540<?php   if ( $bulk ) : ?>
     1541                <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
     1542<?php   endif; // $bulk ?>
     1543                <?php
     1544                /** This filter is documented in wp-admin/includes/meta-boxes.php */
     1545                $default_title = apply_filters( 'default_page_template_title',  __( 'Default Template' ), 'quick-edit' );
     1546                ?>
     1547                <option value="default"><?php echo esc_html( $default_title ); ?></option>
     1548                <?php page_template_dropdown( $post->page_template, $screen->post_type ) ?>
     1549            </select>
     1550        </label>
     1551    <?php endif; ?>
    15551552
    15561553    <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
Note: See TracChangeset for help on using the changeset viewer.