0

I have a custom taxonomy called Product Category, which has a range of parent categories, then each parent one has subsequent child categories.

Is it possible for the archive page i/e taxonomy-product-category.php to drill down in order of categories, not just go direct to the final posts?

Currently it lists the parent categories, clicking on a parent cat takes you to a list of posts only from the child categories NOT a list of the child categories like it should?

So i assume is there a conditional which you can put on the taxonomy-product-category.php if tax parent category show this, else show parent child categories?

Unsure if its possible dynamically.

I've tried the following but no luck..

<?php
$term = get_term_by('slug', get_query_var('term'), 'product-category'); if((int)$term->parent)

get_template_part('product','parent');

else

get_template_part('product','child');

?>

1 Answer 1

0

You can use get_queried_object to return the full queried term object on a taxonomy archive page.

$term = get_queried_object();
if( 0 === $term->parent ){
    // term is top level
} else {
    // term has parent
}

Your Answer

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

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