Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2. $categories = get_terms( 'my-taxonomy', array(
  3. 'hide_empty' => 0,
  4. ) );
  5.  
  6. $subcategories = $subsubcategories = $categories;
  7.  
  8. foreach ( $categories as $category ) {
  9. // Only top level terms
  10. if ( 0 != $category->parent ) {
  11. continue;
  12. }
  13.  
  14. // It is first level, display it
  15. echo '<h2>' . $category->name . '</h2>';
  16. echo '<ul>';
  17.  
  18. foreach ( $subcategories as $subcategory ) {
  19. // Only child terms
  20. if ( $category->term_id != $subcategory->parent ) {
  21. continue;
  22. }
  23.  
  24. // It is second level, display it
  25. echo '<li>' . $subcategory->name;
  26. echo '<ul>';
  27.  
  28. foreach ( $subsubcategories as $subsubcategory ) {
  29. // Only child terms
  30. if ( $subcategory->term_id != $subsubcategory->parent ) {
  31. continue;
  32. }
  33.  
  34. // It is third level, display it
  35. echo '<li style="color:red;">' . $subsubcategory->name . '</li>';
  36. }
  37.  
  38. echo '</ul>';
  39. echo '</li>';
  40. }
  41.  
  42. echo '</ul>';
  43. }
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement