How do I set a specific template for sub-categories?

Question

There’s a few posts about getting sub-categories to use the same template as their parent but I want to do something slightly different.

I have a category 67, and I want all sub-categories of 67 to use a specific template. Not the default template, and not the custom category-67.php template.

How do I do that?

I have the following code in functions.php, but it also seems to change the template of category-67

// use specific template depending on category
function myTemplateSelect() {
    if (is_category() && !is_feed()) {
        if (is_category(get_cat_id('67')) || cat_is_ancestor_of(get_cat_id('67'), get_query_var('cat'))) {
            load_template(TEMPLATEPATH . '/category-slider.php');
            exit;
        }
    }
}

 add_action('template_redirect', 'myTemplateSelect');

Eventually I will want to add a few more categories to this also.

Any ideas?

Thanks

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/how-do-i-set-a-specific-template-for-sub-categories/">

How do I set a specific template for sub-categories?</a>
0
, C-M 2 months 0 Answers 49 views 0

Leave an answer