Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've inherited a Wordpress site that my company built before I started working here. I would go and ask this question of the guy who built it, but he has now left the company.

My query relates to custom templates for wordpress categories. I know that you're able to create a template file called category-.php, and when that category is accessed, it'll use that custom template. In this instance, the file is called 'category-limousin-magazine.php'

That is working fine - my issues relates to the sub-categories of this category, i.e. under Limousin Magazine, I've got categories of 2011, 2010, 2009, 2008, 2007 and 2006. Somehow, when building the site, he was able to get all of these sub-categories to use the template of 'category-limousin-magazine-templates.php' - but I can't figure out how he did it, as when I run the current site, next to an archive copy of the site previously, the category-limousin-magazine-templates.php file is being totally ignored.

So I have one of two questions - first of all, is there an easy way to get multiple categories to use one single template file, or failing that, what is the best way of getting multiple (potentially dynamic) categories from using a custom template.

Thank you.

share|improve this question
1  
Please use get_template_directory() instead of TEMPLATEPATH. And please add your "UPDATE" as answer, so you can accept it and the question doesn't stay open. –  kaiser Oct 19 '12 at 3:51

2 Answers 2

I wrote a plugin a while back that might help make this easier.

http://wordpress.org/extend/plugins/category-template-hierarchy/

share|improve this answer
    
I've actully seen this plugin on my travels while looking into other things, and I like the idea of it. I don't have any need for it right now, but will be keeping it in mind for future projects :) –  Daniel Hollands May 2 '12 at 20:57
up vote 2 down vote accepted

I found the answer - this was in the function.php file - I just needed to update the category ID (long story):

function inherit_template()
{
    if (is_category())
    {
        $catid = get_query_var('cat');
        $cat = &get_category($catid);
        $parent = $cat->category_parent;
        $cat = &get_category($parent);
        if ($cat->cat_ID == 215)
        {
            if (file_exists(TEMPLATEPATH . '/category-limousin-magazine-templates.php'))
            {
                include (TEMPLATEPATH . '/category-limousin-magazine-templates.php');
                exit;
            }
        }
    }
}

add_action('template_redirect', 'inherit_template', 1);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.