Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $categories = get_terms( 'my-taxonomy', array(
- 'hide_empty' => 0,
- ) );
- $subcategories = $subsubcategories = $categories;
- foreach ( $categories as $category ) {
- // Only top level terms
- if ( 0 != $category->parent ) {
- continue;
- }
- // It is first level, display it
- echo '<h2>' . $category->name . '</h2>';
- echo '<ul>';
- foreach ( $subcategories as $subcategory ) {
- // Only child terms
- if ( $category->term_id != $subcategory->parent ) {
- continue;
- }
- // It is second level, display it
- echo '<li>' . $subcategory->name;
- echo '<ul>';
- foreach ( $subsubcategories as $subsubcategory ) {
- // Only child terms
- if ( $subcategory->term_id != $subsubcategory->parent ) {
- continue;
- }
- // It is third level, display it
- echo '<li style="color:red;">' . $subsubcategory->name . '</li>';
- }
- echo '</ul>';
- echo '</li>';
- }
- echo '</ul>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement