Make WordPress Core

Changeset 11814


Ignore:
Timestamp:
08/14/2009 04:56:51 PM (16 years ago)
Author:
westi
Message:

Support location of category templates based on category slug as well as id. Fixes #10614 based on patch from scribu.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/theme.php

    r11545 r11814  
    591591 * Retrieve path of category template in current or parent template.
    592592 *
    593  * Works by retrieving the current category ID, for example 'category-1.php' and
    594  * will fallback to category.php template, if the ID category file doesn't
    595  * exist.
     593 * Works by first retrieving the current slug for example 'category-default.php' and then
     594 * trying category ID, for example 'category-1.php' and will finally fallback to category.php
     595 * template, if those files don't exist.
    596596 *
    597597 * @since 1.5.0
     
    601601 */
    602602function get_category_template() {
    603     $template = locate_template(array("category-" . absint( get_query_var('cat') ) . '.php', 'category.php'));
     603    $cat_ID = absint( get_query_var('cat') );
     604    $category = get_category( $cat_ID );
     605
     606    $templates = array();
     607   
     608    if ( !is_wp_error($category) )
     609        $templates[] = "category-{$category->slug}.php";
     610
     611    $templates[] = "category-$cat_ID.php";
     612    $templates[] = "category.php"; 
     613   
     614    $template = locate_template($templates);
    604615    return apply_filters('category_template', $template);
    605616}
Note: See TracChangeset for help on using the changeset viewer.