Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <ul class="sidebar-menu">
  2. <?php
  3. $parent_terms = get_terms( 'product_cat', array( 'hide_empty' => false, 'parent' => 0 ) );
  4. foreach( $parent_terms as $parent_term ) {
  5. // display top level term name
  6. $child_terms = get_terms( 'product_cat', array( 'hide_empty' => false, 'parent' => $parent_term->term_id ) );
  7. ?>
  8. <li class="cat-item <?php if ($child_terms) { echo "have-children"; } ?>"><a href="<?php echo get_term_link($parent_term); ?>"><?php echo $parent_term->name; ?></a>
  9. <?php if ($child_terms) : ?>
  10. <ul class="children">
  11. <?php foreach( $child_terms as $child_term ) : ?>
  12. <!-- Display name of all childs of the parent term -->
  13. <li class="cat-item"><a href="<?php echo get_term_link($child_term); ?>"><?php echo $child_term->name; ?></a></li>
  14. <?php endforeach; ?>
  15. </ul>
  16. <?php endif; ?>
  17. </li>
  18. <?php
  19. }
  20. ?>
  21. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement