Make WordPress Core

Changeset 12135


Ignore:
Timestamp:
11/01/2009 10:18:34 AM (14 years ago)
Author:
westi
Message:

Improve get_page_template() to search based on slug and id as well. Fixes #11055 props aaroncampbell.

File:
1 edited

Legend:

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

    r12134 r12135  
    828828 * Retrieve path of page template in current or parent template.
    829829 *
    830  * First attempt is to look for the file in the '_wp_page_template' page meta
    831  * data. The second attempt, if the first has a file and is not empty, is to
    832  * look for 'page.php'.
     830 * Will first look for the specifically assigned page template
     831 * The will search for 'page-{slug}.php' followed by 'page-id.php'
     832 * and finally 'page.php'
    833833 *
    834834 * @since 1.5.0
     
    841841    $id = (int) $wp_query->post->ID;
    842842    $template = get_post_meta($id, '_wp_page_template', true);
     843    $pagename = get_query_var('pagename');
    843844
    844845    if ( 'default' == $template )
     
    848849    if ( !empty($template) && !validate_file($template) )
    849850        $templates[] = $template;
    850 
     851    if ( $pagename )
     852        $templates[] = "page-$pagename.php";
     853    if ( $id )
     854        $templates[] = "page-$id.php";
    851855    $templates[] = "page.php";
    852856
Note: See TracChangeset for help on using the changeset viewer.