Ticket #12877: 12877.2.patch
File 12877.2.patch, 6.6 KB (added by , 14 years ago) |
---|
-
wp-includes/template-loader.php
18 18 return; 19 19 endif; 20 20 21 if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) : 22 $template = false; 23 if ( is_404() && $template = get_404_template() ) : 24 elseif ( is_search() && $template = get_search_template() ) : 25 elseif ( is_tax() && $template = get_taxonomy_template() ) : 26 elseif ( is_home() && $template = get_home_template() ) : 27 elseif ( is_attachment() && $template = get_attachment_template() ) : 28 remove_filter('the_content', 'prepend_attachment'); 29 elseif ( is_single() && $template = get_single_template() ) : 30 elseif ( is_page() && $template = get_page_template() ) : 31 elseif ( is_category() && $template = get_category_template() ) : 32 elseif ( is_tag() && $template = get_tag_template() ) : 33 elseif ( is_author() && $template = get_author_template() ) : 34 elseif ( is_date() && $template = get_date_template() ) : 35 elseif ( is_archive() && $template = get_archive_template() ) : 36 elseif ( is_comments_popup() && $template = get_comments_popup_template() ) : 37 elseif ( is_paged() && $template = get_paged_template() ) : 38 else : 39 $template = get_index_template(); 21 /** 22 * Locates and loads the template for current page ($wp_query). 23 * 24 * @since 3.1.0 25 */ 26 function template_loader() { 27 if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) : 28 $template = false; 29 if ( is_404() && $template = get_404_template() ) : 30 elseif ( is_search() && $template = get_search_template() ) : 31 elseif ( is_tax() && $template = get_taxonomy_template() ) : 32 elseif ( is_home() && $template = get_home_template() ) : 33 elseif ( is_attachment() && $template = get_attachment_template() ) : 34 remove_filter('the_content', 'prepend_attachment'); 35 elseif ( is_single() && $template = get_single_template() ) : 36 elseif ( is_page() && $template = get_page_template() ) : 37 elseif ( is_category() && $template = get_category_template() ) : 38 elseif ( is_tag() && $template = get_tag_template() ) : 39 elseif ( is_author() && $template = get_author_template() ) : 40 elseif ( is_date() && $template = get_date_template() ) : 41 elseif ( is_archive() && $template = get_archive_template() ) : 42 elseif ( is_comments_popup() && $template = get_comments_popup_template() ) : 43 elseif ( is_paged() && $template = get_paged_template() ) : 44 else : 45 $template = get_index_template(); 46 endif; 47 if ( $template = apply_filters( 'template_include', $template ) ) 48 include( $template ); 49 return; 40 50 endif; 41 if ( $template = apply_filters( 'template_include', $template ) ) 42 include( $template ); 43 return; 44 endif; 51 } 45 52 53 update_template_hierarchy(); 54 template_loader(); 55 return; 56 46 57 ?> 58 No newline at end of file -
wp-includes/theme.php
989 989 * @return string The template filename if one is located. 990 990 */ 991 991 function locate_template($template_names, $load = false) { 992 $template_names = apply_filters('locate_template', $template_names); 993 992 994 if ( !is_array($template_names) ) 993 995 return ''; 994 996 … … 1030 1032 } 1031 1033 1032 1034 /** 1035 * Creates a global variable that contains the template hierarchy for the current page. 1036 * 1037 * Calling update_template_hierarchy() will recalculate the template hierarchy for $wp_query. 1038 * 1039 * @uses template_loader() Calculates the template hierarchy. 1040 * @since 3.1.0 1041 */ 1042 function update_template_hierarchy() { 1043 global $wp_template_hierarchy; 1044 1045 add_filter('locate_template', '_record_template_hierarchy'); 1046 add_filter('template_include', '__return_false'); 1047 $wp_template_hierarchy = array(); 1048 template_loader(); 1049 remove_filter('locate_template', '_record_template_hierarchy'); 1050 remove_filter('template_include', '__return_false'); 1051 $wp_template_hierarchy = call_user_func_array('array_merge', $wp_template_hierarchy); 1052 } 1053 1054 /** 1055 * Returns the template hierarchy for the current page. 1056 * 1057 * @since 3.1.0 1058 * 1059 * @return array 1060 */ 1061 function get_template_hierarchy() { 1062 global $wp_template_hierarchy; 1063 return $wp_template_hierarchy; 1064 } 1065 1066 /** 1067 * Private function to modify locate_template() when updating the 1068 * template hierarchy. 1069 * 1070 * Records $template_names in $wp_template_hierarchy, then returns false 1071 * which causes locate_template() to fail. 1072 * 1073 * @since 3.1.0 1074 * @access private 1075 * 1076 * @param array $template_names Template files to look for in locate_template. 1077 * @return array 1078 */ 1079 function _record_template_hierarchy( $template_names ) { 1080 global $wp_template_hierarchy; 1081 $wp_template_hierarchy[] = $template_names; 1082 return false; 1083 } 1084 1085 /** 1033 1086 * Display localized stylesheet link element. 1034 1087 * 1035 1088 * @since 2.1.0 -
wp-includes/general-template.php
126 126 } 127 127 128 128 /** 129 * Load a template from a folder based upon the best match from the template hierarchy. 130 * 131 * Makes it easy for a theme to reuse sections of code in a easy to overload way 132 * for child themes. 133 * 134 * Includes a template from a folder within a theme based upon the most specific 135 * match from the template hierarchy. If the folder contains no matching files 136 * then no template will be included. 137 * 138 * @uses get_template_hierarchy() To build template file names. 139 * @uses locate_template() To search for template files. 140 * @since 3.1.0 141 * 142 * @param string $folder The name of the folder to be searched. 143 * @return string The file path to the loaded file. The empty string if no file was found. 144 */ 145 function get_template_module( $folder ) { 146 $template_hierarchy = get_template_hierarchy(); 147 $template_names = array(); 148 foreach( $template_hierarchy as $template_name ) { 149 $template_names[] = $folder . '/' . $template_name; 150 } 151 $located = locate_template($template_names); 152 if( $located ) 153 include( $located ); 154 return $located; 155 } 156 157 /** 129 158 * Display search form. 130 159 * 131 160 * Will first attempt to locate the searchform.php file in either the child or