diff --git a/wp-blog-header.php b/wp-blog-header.php index 40fe0ab90f..3899ee745d 100644 --- a/wp-blog-header.php +++ b/wp-blog-header.php @@ -225,41 +225,38 @@ if ($pagenow == 'index.php') { } else if ( is_trackback() ) { include(ABSPATH . '/wp-trackback.php'); exit; - } else if ( is_404() && file_exists("$wp_template_dir/404.php") ) { - include("$wp_template_dir/404.php"); + } else if ( is_404() && get_404_template() ) { + include(get_404_template()); exit; - } else if ( is_home() && file_exists("$wp_template_dir/index.php") ) { - include("$wp_template_dir/index.php"); + } else if ( is_home() && get_home_template() ) { + include(get_home_template()); exit; - } else if ( is_single() && file_exists("$wp_template_dir/single.php") ) { - include("$wp_template_dir/single.php"); + } else if ( is_single() && get_single_template() ) { + include(get_single_template()); exit; - } else if ( is_page() && file_exists(get_page_template()) ) { + } else if ( is_page() && get_page_template() ) { include(get_page_template()); exit; - } else if ( is_category() && file_exists("$wp_template_dir/category-" . get_query_var('cat') . '.php') ) { - include("$wp_template_dir/category-" . get_query_var('cat') . '.php'); + } else if ( is_category() && get_category_template()) { + include(get_category_template()); exit; - } else if ( is_category() && file_exists("$wp_template_dir/category.php") ) { - include("$wp_template_dir/category.php"); + } else if ( is_author() && get_author_template() ) { + include(get_author_template()); exit; - } else if ( is_author() && file_exists("$wp_template_dir/author.php") ) { - include("$wp_template_dir/author.php"); + } else if ( is_date() && get_date_template() ) { + include(get_date_template()); exit; - } else if ( is_date() && file_exists("$wp_template_dir/date.php") ) { - include("$wp_template_dir/date.php"); + } else if ( is_archive() && get_archive_template() ) { + include(get_archive_template()); exit; - } else if ( is_archive() && file_exists("$wp_template_dir/archive.php") ) { - include("$wp_template_dir/archive.php"); + } else if ( is_search() && get_search_template() ) { + include(get_search_template()); exit; - } else if ( is_search() && file_exists("$wp_template_dir/search.php") ) { - include("$wp_template_dir/search.php"); + } else if ( is_paged() && get_paged_template() ) { + include(get_paged_template()); exit; - } else if ( is_paged() && file_exists("$wp_template_dir/paged.php") ) { - include("$wp_template_dir/paged.php"); - exit; - } else if ( file_exists("$wp_template_dir/index.php") ) { - include("$wp_template_dir/index.php"); + } else if ( file_exists(TEMPLATEPATH . "/index.php") ) { + include(TEMPLATEPATH . "/index.php"); exit; } } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index b9e7b525da..ed39a2dac8 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1452,24 +1452,77 @@ function get_current_theme() { return $current_theme; } +function get_query_template($type) { + $template = ''; + if ( file_exists(TEMPLATEPATH . "/{$type}.php") ) + $template = TEMPLATEPATH . "/{$type}.php"; + + return apply_filters("{$type}_template", $template); +} + +function get_404_template() { + return get_query_template('404'); +} + +function get_archive_template() { + return get_query_template('archive'); +} + +function get_author_template() { + return get_query_template('author'); +} + +function get_category_template() { + $template = ''; + if ( file_exists(TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php') ) + $template = TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php'; + else if ( file_exists(TEMPLATEPATH . "/category.php") ) + $template = TEMPLATEPATH . "/category.php"; + + return apply_filters('category_template', $template); +} + +function get_date_template() { + return get_query_template('date'); +} + +function get_home_template() { + $template = ''; + if ( file_exists(TEMPLATEPATH . "/index.php") ) + $template = TEMPLATEPATH . "/index.php"; + + return apply_filters('home_template', $template); +} + function get_page_template() { global $wp_query; $id = $wp_query->post->ID; - $template_dir = get_template_directory(); - $default = "$template_dir/page.php"; - $template = get_post_meta($id, '_wp_page_template', true); - if (empty($template) || ($template == 'default')) { - return $default; - } + if ( 'default' == $template ) + $template = ''; - if (file_exists("$template_dir/$template")) { - return "$template_dir/$template"; - } + if ( ! empty($template) && file_exists(TEMPLATEPATH . "/$template") ) + $template = TEMPLATEPATH . "/$template"; + else if ( file_exists(TEMPLATEPATH . "/page.php") ) + $template = TEMPLATEPATH . "/page.php"; + else + $template = ''; - return $default; + return apply_filters('page_template', $template); +} + +function get_paged_template() { + return get_query_template('paged'); +} + +function get_search_template() { + return get_query_template('search'); +} + +function get_single_template() { + return get_query_template('single'); } // Borrowed from the PHP Manual user notes. Convert entities, while