views:

138

answers:

2

I've got a category template: category-projects.php

This category has subcategories, but they're refering to the template category.php for instructions instead of the parent category. How do I make subcategories refer to parent category templates in the cascading order of template references?

*Note, I'm talking about category level urls, not posts.

+1  A: 

As far i know; according to wp template hierarchy, category-samplecat.php is only applies to a category with slug name "samplecat". So it's not possible to do it in this way.

But in the category.php file (that applies to every category which hasn't a special template file) you can make a conditional check if current category is a child of "project" (using this method in my answer to your other question) and if so you can apply same structure of category-projects.php to it or include category-projects.php.

gasoved
+2  A: 

I think the best way to do this is to hook into the template_redirect action in your functions.php file.

function myTemplateSelect()
{
    if (is_category() && !is_feed()) {
        if (is_category(get_cat_id('projects')) || cat_is_ancestor_of(get_cat_id('projects'), get_query_var('cat'))) {
            load_template(TEMPLATEPATH . '/category-projects.php');
            exit;
        }
    }
}

add_action('template_redirect', 'myTemplateSelect');
Richard M
Woooooahhhhhh! That's awesome! Is there any way to abstract it out further, and have it apply to ALL subcategories of ALL categories, rather than declaring them each literally?
Matrym
TheDeadMedic's answer to your subsequent question should work.
Richard M
http://stackoverflow.com/questions/3119961/make-all-wordpress-categories-use-their-parent-category-template
Matrym