Plugin WP : Category Parent Template

This is my first plugin and also my first article in English, I think it will be an useful plugin for WordPress community. As a wordpress theme designer, I faced many times this problem, how can I use only two categories templates ? One for my articles listed in my portfolio and one for my articles listed in my blog without needing to create templates for my subcategories ?

Child category will use template of parent category

Download the plugin

Download : parent-category-template.php and install it via your WordPress Administration : Plugins > Add New > Upload
If there is no template for your subcategories, WordPress will use the parent category.

Or do it yourself

Copy this code in your functions.php.

function load_cat_parent_template()
    global $wp_query;

    if (!$wp_query->is_category)
        return true; // saves a bit of nesting

    // get current category object
    $cat = $wp_query->get_queried_object();

    // trace back the parent hierarchy and locate a template
    while ($cat && !is_wp_error($cat)) {
        $template = TEMPLATEPATH . "/category-{$cat->slug}.php";

        if (file_exists($template)) {

        $cat = $cat->parent ? get_category($cat->parent) : false;
add_action('template_redirect', 'load_cat_parent_template');

Thanks to for this useful code

Pour les Français qui galèrent en anglais :