Support » Fixing WordPress » List Taxonomy Terms In Hierarchy

  • kcomphlint

    (@kcomphlint)


    I have this code in a template for a custom post type:

    <?php
    	if (get_the_terms($post->ID, 'practice_area')) {
    		$taxonomy_ar = get_the_terms($post->ID, 'practice_area');
    		if (count($taxonomy_ar) > 0){
    		  foreach ($taxonomy_ar as $taxonomy_term) {
    		    $output .= '<li><a href="'.get_home_url().'/practice_area/'.$taxonomy_term->slug.'/">'. $taxonomy_term->name .'</a></li>';
    		  }
    	?>
    	<ul class="atty-info">
    	<?php
    	  echo $output;
    	?>
    	</ul>
    	<?php
    		}
    	}
    	//End Practice Areas
    	?>

    This code goes in a profile for an attorney and it lists the Practice Areas that the attorney works in. Those areas are a taxonomy. When the list outputs now, it is just an unordered list. I would like for it to show the heirarchy of the taxonomy.

    How it is now:

    • Practice Area 1
    • Practice Area 1.1
    • Practice Area 1.2
    • Practice Area 2

    How I want it to look:

    • Practice Area 1
      • Practice Area 1.1
      • Practice Area 1.2
    • Practice Area 2
  • The topic ‘List Taxonomy Terms In Hierarchy’ is closed to new replies.