Ticket #14310: template_hierarchy.2.diff
File template_hierarchy.2.diff, 4.4 KB (added by , 14 years ago) |
---|
-
wp-includes/theme.php
687 687 } 688 688 689 689 /** 690 * Retrieve path to file without the use of extension.690 * Retrieve path to a template 691 691 * 692 * Used to quickly retrieve the path of file without including the file693 * extension. It will also check the parent t emplate, if the file exists, with694 * the use of {@link locate_template()}. Allows for more generic file location692 * Used to quickly retrieve the path of a template without including the file 693 * extension. It will also check the parent theme, if the file exists, with 694 * the use of {@link locate_template()}. Allows for more generic template location 695 695 * without the use of the other get_*_template() functions. 696 696 * 697 * Can be used with include() or require() to retrieve path.698 * <code>699 * if( '' != get_query_template( '404' ) )700 * include( get_query_template( '404' ) );701 * </code>702 * or the same can be accomplished with703 * <code>704 * if( '' != get_404_template() )705 * include( get_404_template() );706 * </code>707 *708 697 * @since 1.5.0 709 698 * 710 699 * @param string $type Filename without extension. 700 * @param array $templates An optional list of template candidates 711 701 * @return string Full path to file. 712 702 */ 713 function get_query_template( $type) {703 function get_query_template( $type, $templates = array() ) { 714 704 $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); 715 return apply_filters("{$type}_template", locate_template(array("{$type}.php"))); 705 706 if ( empty( $templates ) ) 707 $templates = array("{$type}.php"); 708 709 $templates = apply_filters( "{$type}_template_hierarchy", $templates ); 710 711 return apply_filters( "{$type}_template", locate_template( $templates ) ); 716 712 } 717 713 718 714 /** … … 768 764 $templates[] = "author-{$author_id}.php"; 769 765 $templates[] = 'author.php'; 770 766 771 $template = locate_template( $templates ); 772 return apply_filters( 'author_template', $template ); 767 return get_query_template( 'author', $templates ); 773 768 } 774 769 775 770 /** … … 790 785 791 786 $templates = array(); 792 787 793 if ( !is_wp_error( $category) )788 if ( !is_wp_error( $category ) ) 794 789 $templates[] = "category-{$category->slug}.php"; 795 790 796 791 $templates[] = "category-$cat_ID.php"; 797 792 $templates[] = "category.php"; 798 793 799 $template = locate_template($templates); 800 return apply_filters('category_template', $template); 794 return get_query_template( 'category', $templates ); 801 795 } 802 796 803 797 /** … … 824 818 $templates[] = "tag-$tag_id.php"; 825 819 $templates[] = "tag.php"; 826 820 827 $template = locate_template($templates); 828 return apply_filters('tag_template', $template); 821 return get_query_template( 'tag', $templates ); 829 822 } 830 823 831 824 /** … … 857 850 858 851 $templates[] = "taxonomy.php"; 859 852 860 $template = locate_template($templates); 861 return apply_filters('taxonomy_template', $template); 853 return get_query_template( 'taxonomy', $templates ); 862 854 } 863 855 864 856 /** … … 885 877 * @return string 886 878 */ 887 879 function get_home_template() { 888 $template = locate_template(array('home.php', 'index.php')); 889 return apply_filters('home_template', $template); 880 $templates = array( 'home.php', 'index.php' ); 881 882 return get_query_template( 'home', $templates ); 890 883 } 891 884 892 885 /** … … 900 893 * @return string 901 894 */ 902 895 function get_front_page_template() { 903 return apply_filters( 'front_page_template', locate_template( array('front-page.php') ) ); 896 $templates = array('front-page.php'); 897 898 return get_query_template( 'front_page', $templates ); 904 899 } 905 900 906 901 /** … … 939 934 $templates[] = "page-$id.php"; 940 935 $templates[] = "page.php"; 941 936 942 return apply_filters('page_template', locate_template($templates));937 return get_query_template( 'page', $templates ); 943 938 } 944 939 945 940 /** … … 976 971 977 972 $object = $wp_query->get_queried_object(); 978 973 $templates = array('single-' . $object->post_type . '.php', 'single.php'); 979 return apply_filters('single_template', locate_template($templates)); 974 975 return get_query_template( 'single', $templates ); 980 976 } 981 977 982 978 /** … … 1019 1015 * @return string 1020 1016 */ 1021 1017 function get_comments_popup_template() { 1022 $template = locate_template(array("comments-popup.php"));1018 $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) ); 1023 1019 1024 1020 // Backward compat code will be removed in a future release 1025 1021 if ('' == $template) 1026 1022 $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php'; 1027 1023 1028 return apply_filters('comments_popup_template', $template);1024 return $template; 1029 1025 } 1030 1026 1031 1027 /**