Make WordPress Core


Ignore:
Timestamp:
10/26/2016 08:06:43 AM (8 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/post/template.php

    r38523 r38951  
    272272    /**
    273273     * @ticket 31389
     274     * @ticket 18375
    274275     */
    275276    public function test_get_page_template_slug_non_page() {
    276         $post_id = self::factory()->post->create( array(
    277             'post_type' => 'post',
    278         ) );
    279 
    280         $this->assertFalse( get_page_template_slug( $post_id ) );
     277        $post_id = self::factory()->post->create();
     278
     279        $this->assertEquals( '', get_page_template_slug( $post_id ) );
     280
     281        update_post_meta( $post_id, '_wp_page_template', 'default' );
     282
     283        $this->assertEquals( '', get_page_template_slug( $post_id ) );
     284
     285        update_post_meta( $post_id, '_wp_page_template', 'example.php' );
     286        $this->assertEquals( 'example.php', get_page_template_slug( $post_id ) );
     287    }
     288
     289    /**
     290     * @ticket 18375
     291     */
     292    public function test_get_page_template_slug_non_page_from_loop() {
     293        $post_id = self::factory()->post->create();
     294
     295        update_post_meta( $post_id, '_wp_page_template', 'example.php' );
    281296
    282297        $this->go_to( get_permalink( $post_id ) );
    283         $this->assertFalse( get_page_template_slug() );
     298
     299        $this->assertEquals( 'example.php', get_page_template_slug() );
    284300    }
    285301
Note: See TracChangeset for help on using the changeset viewer.