Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ul class="sidebar-menu">
- <?php
- $parent_terms = get_terms( 'product_cat', array( 'hide_empty' => false, 'parent' => 0 ) );
- foreach( $parent_terms as $parent_term ) {
- // display top level term name
- $child_terms = get_terms( 'product_cat', array( 'hide_empty' => false, 'parent' => $parent_term->term_id ) );
- ?>
- <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>
- <?php if ($child_terms) : ?>
- <ul class="children">
- <?php foreach( $child_terms as $child_term ) : ?>
- <!-- Display name of all childs of the parent term -->
- <li class="cat-item"><a href="<?php echo get_term_link($child_term); ?>"><?php echo $child_term->name; ?></a></li>
- <?php endforeach; ?>
- </ul>
- <?php endif; ?>
- </li>
- <?php
- }
- ?>
- </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement