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

git-svn-id: http://svn.automattic.com/wordpress/trunk@12135 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2009-11-01 10:18:34 +00:00
parent 7251aff3f3
commit a980ec773a
1 changed files with 8 additions and 4 deletions

View File

@ -827,9 +827,9 @@ function get_home_template() {
/** /**
* Retrieve path of page template in current or parent template. * Retrieve path of page template in current or parent template.
* *
* First attempt is to look for the file in the '_wp_page_template' page meta * Will first look for the specifically assigned page template
* data. The second attempt, if the first has a file and is not empty, is to * The will search for 'page-{slug}.php' followed by 'page-id.php'
* look for 'page.php'. * and finally 'page.php'
* *
* @since 1.5.0 * @since 1.5.0
* *
@ -840,6 +840,7 @@ function get_page_template() {
$id = (int) $wp_query->post->ID; $id = (int) $wp_query->post->ID;
$template = get_post_meta($id, '_wp_page_template', true); $template = get_post_meta($id, '_wp_page_template', true);
$pagename = get_query_var('pagename');
if ( 'default' == $template ) if ( 'default' == $template )
$template = ''; $template = '';
@ -847,7 +848,10 @@ function get_page_template() {
$templates = array(); $templates = array();
if ( !empty($template) && !validate_file($template) ) if ( !empty($template) && !validate_file($template) )
$templates[] = $template; $templates[] = $template;
if ( $pagename )
$templates[] = "page-$pagename.php";
if ( $id )
$templates[] = "page-$id.php";
$templates[] = "page.php"; $templates[] = "page.php";
return apply_filters('page_template', locate_template($templates)); return apply_filters('page_template', locate_template($templates));