From 23a106b6d059532fd0c43e23973d98ae893b7672 Mon Sep 17 00:00:00 2001 From: westi Date: Fri, 14 Aug 2009 16:56:51 +0000 Subject: [PATCH] Support location of category templates based on category slug as well as id. Fixes #10614 based on patch from scribu. git-svn-id: http://svn.automattic.com/wordpress/trunk@11814 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/theme.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 9d56a6403d..b3a5acb418 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -590,9 +590,9 @@ function get_author_template() { /** * Retrieve path of category template in current or parent template. * - * Works by retrieving the current category ID, for example 'category-1.php' and - * will fallback to category.php template, if the ID category file doesn't - * exist. + * Works by first retrieving the current slug for example 'category-default.php' and then + * trying category ID, for example 'category-1.php' and will finally fallback to category.php + * template, if those files don't exist. * * @since 1.5.0 * @uses apply_filters() Calls 'category_template' on file path of category template. @@ -600,7 +600,18 @@ function get_author_template() { * @return string */ function get_category_template() { - $template = locate_template(array("category-" . absint( get_query_var('cat') ) . '.php', 'category.php')); + $cat_ID = absint( get_query_var('cat') ); + $category = get_category( $cat_ID ); + + $templates = array(); + + if ( !is_wp_error($category) ) + $templates[] = "category-{$category->slug}.php"; + + $templates[] = "category-$cat_ID.php"; + $templates[] = "category.php"; + + $template = locate_template($templates); return apply_filters('category_template', $template); }