I have 2 custom taxonomies, each with a number of terms:
tax1
term1_1
term1_2
tax2
term2_1
term2_2
term2_3
I am trying to have each taxonomy usea different template file for each its single-term archive pages. I.E. term1_1 and term1_2
use one template, while term2_1 - 3
use a second one. I can of course just load different php files conditionally from the main archive.php
file – but I would like to know if there is a way to do this within the standard template hierarchy.
As far as I can tell, taxonomy-tax1.php doesn’t work for this (unless I’m messing up royally)
I would intercept the template loader at
template_redirect
:Then, you would check to see if the query is a custom taxonomy:
Next, get the term object, and find out if it has a parent:
So, putting it all together:
Check WordPress Template Hierarchy. As you can see you can use pattern
taxonomy-$taxonomy-$term.php
to specify template for specific taxonomy and term. In your case it will betaxonomy-tax1-term1_1.php
, etc.Modify the conditionals to target you archive page. I would use template_include like this :
I would NOT use template redirect as advised by Lead Developer Mark Jaquith.