Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @@hthis part goes into the template:
- <?php
- hierarchical_category_tree( 0 ); // the function call; 0 for all categories; or cat ID
- ?>
- @@hthis goes into functions.php of your theme
- function hierarchical_category_tree( $cat ) {
- static $depth=0;
- // wpse-41548 // v1.3 // structured nested list // alchymyth // a hierarchical list of all categories //
- $next = get_categories('hide_empty=0&orderby=name&order=ASC&parent=' . $cat);
- if( $next ) :
- $depth++;
- echo "\n"; for($i=1;$i<$depth;$i++) echo ' '; //for structured html output
- echo '<ul class="depth-'.$depth.'">';
- foreach( $next as $cat ) :
- echo "\n "; for($i=1;$i<$depth;$i++) echo ' '; //for structured html output
- echo '<li><a href="' . get_category_link( $cat->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $cat->name ) . '">' . $cat->name . '</a>';
- hierarchical_category_tree( $cat->term_id );
- echo '</li>';
- endforeach;
- echo "\n"; for($i=1;$i<$depth;$i++) echo ' '; //for structured html output
- echo '</ul><!--/.depth-'.$depth.'-->';
- $depth--;
- echo "\n "; for($i=1;$i<$depth;$i++) echo ' '; //for structured html output
- endif;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement