Support location of category templates based on category slug as well as id. Fixes #10614 based on patch from scribu.
git-svn-id: https://develop.svn.wordpress.org/trunk@11814 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ddbdf401d4
commit
9e32cf358c
@ -590,9 +590,9 @@ function get_author_template() {
|
|||||||
/**
|
/**
|
||||||
* Retrieve path of category template in current or parent template.
|
* Retrieve path of category template in current or parent template.
|
||||||
*
|
*
|
||||||
* Works by retrieving the current category ID, for example 'category-1.php' and
|
* Works by first retrieving the current slug for example 'category-default.php' and then
|
||||||
* will fallback to category.php template, if the ID category file doesn't
|
* trying category ID, for example 'category-1.php' and will finally fallback to category.php
|
||||||
* exist.
|
* template, if those files don't exist.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
* @uses apply_filters() Calls 'category_template' on file path of category template.
|
* @uses apply_filters() Calls 'category_template' on file path of category template.
|
||||||
@ -600,7 +600,18 @@ function get_author_template() {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function get_category_template() {
|
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);
|
return apply_filters('category_template', $template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user