I would like to know what is the best way to create a different template for parent and children categories and/or taxonomies.

Example: I have a taxonomy called region, which I want to divide in countries, and cities inside countries. So, I will have a parent taxonomy term called Italy, and it’s children taxonomy terms, Rome, Milan, Napoli, whatever. Is it possible to have different templates for country and city? How can I achieve this? Thanks in advance.

2 Answers
2

I suggest creating 3 files

1) regiontemplate-country.php

2) regiontemplate-city.php

These 2 will contain the templates for country & city, then

3) taxonomy-region.php

In this file, add the code to load the appropriate template

<?php
$term = get_term_by('slug', get_query_var('term'), 'region');
if((int)$term->parent)
    get_template_part('regiontemplate', 'city');
else
    get_template_part('regiontemplate', 'country');

Leave a Reply

Your email address will not be published. Required fields are marked *