0

I have a taxonomy called "location" where I have the term "Asia" and the sub-term "Thailand".

Now I created the taxonomy archive template file according to the Wordpress Codex, which is working in the following format:

  • taxonomy-$taxonomy-$term.php --> taxonomy-location-Asia.php

Is there a possibility to create a template file also for the subterm, as following:

  • taxonomy-$taxonomy-$term-$subterm.php --> taxonomy-location-Asia-Thailand.php
2

Strictly speaking, according to the Template Hierarchy, you cannot. Unfortunately

taxonomy-$taxonomy-$term-$subterm.php

is not provided for in default, so this file structure will not work. The best you can do here is

taxonomy-$taxonomy-$term.php

So for Thailand you will name your template as follows

taxonomy-location-Thailand.php

EDIT

Just to add to my answer, the file structure that you are looking for, it is doable outside the template hierarchy. You will just need to use the template_include filter hook to "redirect" Wordpress to use that specific template

function wpse_template_include( $original_template ) {
    if ( has_term( 'Thailand', 'location' )  ) {
        return get_template_directory() . '/ taxonomy-location-Asia-Thailand.php';
    } else {
        return $original_template;
    }
}

add_filter( 'template_include', 'wpse_template_include' );
  • Thanks for your solution. taxonomy-$taxonomy-$term.php is working fine, also for subterms. As for the redirect I need another code, as I am having more than one country and I do not want to have a functions-code for each country. Is there a solution to check if there it is a subterm and if yes, take the name of the parent term into the permalink? – Traveler Jul 8 '14 at 10:53
  • If I understand you correctly here, country will be a term, like ASIA. If a subterm belongs to a term, say Thailand is your subterm of the term ASIA, the template for ASIA should be used, ie, taxonomy-location-Asia.php should be used for all subterms in Asia – Pieter Goosen Jul 8 '14 at 12:38
  • If I am using the format taxonomy-$taxonomy-$term.php, my permalinks will look like following: www.domain.tld/location/thailand. And this is what I would like to have: www.domain.tld/location/asia/thailand. Is there a possibility to realize that for all subterms in one function? Thanks for your support! – Traveler Jul 8 '14 at 12:53
  • I not very comfortable with rewrite rules, sorry. I would advise you to start a new question on this topic. Sorry that I can't be of any help here – Pieter Goosen Jul 8 '14 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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