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/tests/phpunit/tests/query/conditionals.php

    r38938 r38951  
    10451045
    10461046    /**
     1047     * @ticket 18375
     1048     */
     1049    function test_is_page_template_other_post_type() {
     1050        $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) );
     1051        update_post_meta( $post_id, '_wp_page_template', 'example.php' );
     1052        $this->go_to( get_post_permalink( $post_id ) );
     1053        $this->assertFalse( is_page_template( array( 'test.php' ) ) );
     1054        $this->assertTrue( is_page_template( array( 'test.php', 'example.php' ) ) );
     1055    }
     1056
     1057    /**
    10471058     * @ticket 35902
    10481059     */
Note: See TracChangeset for help on using the changeset viewer.