Support » Fixing WordPress » display hierarchical taxonomy list

  • Hello! I need to display my hierarchical custom taxonomy like this:


    I used echo get_the_term_list( $post->ID, ‘my-taxonomy’ );
    but it doesn’t display hierarchy. Any helps? Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer


    Try it with this:

    $taxonomy = 'category'; // change this to your taxonomy
    $terms = wp_get_post_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
      echo '<ul>';
      $terms = trim( implode( ',', (array) $terms ), ' ,' );
      wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms );
      echo '</ul>';

    That’s great!!! Thank you so much!!!
    Now, i need to get image associated with terms. In my old code, i used this :

    <img src=”<?php echo z_taxonomy_image_url($cat->term_id); ?>/>

    with the plugin “Categories Images”.
    How can create a custom list like:

    -child -image
    -child -image
    -child -image

    I suppose i need to attach code between the
    <li></li> elements inside wp_list_categories, isn’t it?

    Moderator keesiemeijer


    Can you show the old code and output? Was the image inside the term link or outside it? Do parent terms have a image?

    in my old code i echoed terms and image. I can associate image and terms with the plugin “Category Images” :

    <?php foreach (wp_get_post_terms($post->ID,'my-taxonomy') as $cat) : ?>
    <li  style="display:inline-block;">
    <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>/>
    <p><?php echo $cat->name; ?></p>
    <?php endforeach; ?>

    Parents (in this case “Colori”) don’t need image associated, but it’s not a problem. The output :

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘display hierarchical taxonomy list’ is closed to new replies.