conditional tags - IF taxonomy archive is hierarchical THEN

admin2025-06-03  4

I'm trying to put in a conditional in my archive.php that sorts our whether the taxonomy is hierarchical or not. This is what I have so far but it doesn't work.

<?php if ( is_taxonomy_hierarchical() ) { ?>
I am a hierarchical tax 
<?php } else { ?>
I am NOT a hierarchical tax 
<?php } ?>

I'm trying to put in a conditional in my archive.php that sorts our whether the taxonomy is hierarchical or not. This is what I have so far but it doesn't work.

<?php if ( is_taxonomy_hierarchical() ) { ?>
I am a hierarchical tax 
<?php } else { ?>
I am NOT a hierarchical tax 
<?php } ?>
Share Improve this question asked Feb 2, 2019 at 3:38 PetePete 1,0582 gold badges14 silver badges40 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Look at the docs (please read the docs) for is_taxonomy_hierarchical(). You need to tell it which taxonomy you're checking:

if ( is_taxonomy_hierarchical( 'my_taxonomy_name' ) ) {

}

If you're template isn't specific to a taxonomy, and you need to know which taxonomy you're viewing, use get_queried_object() to figure it out (you were already told how to do this, by the way):

if ( is_tax() ) {
    $taxonomy = get_queried_object()->taxonomy;

    if ( is_taxonomy_hierarchical( $taxonomy ) ) {

    } else {

    }
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748951824a315101.html

最新回复(0)