1

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.

1
  • 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, 2012 at 3:51

3 Answers 3

2

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);
-1

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

1
  • 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 :) May 2, 2012 at 20:57
-2

Found this plugin and seems like it overrides the category page using some custom post type and seems to be a better alternative.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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