From 2c459fea5e09d1c6c0ac4d81bf1d278cf3a36837 Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Sun, 1 Nov 2009 10:18:34 +0000 Subject: [PATCH] Improve get_page_template() to search based on slug and id as well. Fixes #11055 props aaroncampbell. git-svn-id: https://develop.svn.wordpress.org/trunk@12135 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/theme.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index f92c2ab2ad..a7ab4378db 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -827,9 +827,9 @@ function get_home_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 - * data. The second attempt, if the first has a file and is not empty, is to - * look for 'page.php'. + * Will first look for the specifically assigned page template + * The will search for 'page-{slug}.php' followed by 'page-id.php' + * and finally 'page.php' * * @since 1.5.0 * @@ -840,6 +840,7 @@ function get_page_template() { $id = (int) $wp_query->post->ID; $template = get_post_meta($id, '_wp_page_template', true); + $pagename = get_query_var('pagename'); if ( 'default' == $template ) $template = ''; @@ -847,7 +848,10 @@ function get_page_template() { $templates = array(); if ( !empty($template) && !validate_file($template) ) $templates[] = $template; - + if ( $pagename ) + $templates[] = "page-$pagename.php"; + if ( $id ) + $templates[] = "page-$id.php"; $templates[] = "page.php"; return apply_filters('page_template', locate_template($templates));