Advertisement
alchymyth

category tree

Jul 19th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. @@hthis part goes into the template:
  2.  
  3. <?php      
  4. hierarchical_category_tree( 0 ); // the function call; 0 for all categories; or cat ID
  5. ?>
  6.  
  7. @@hthis goes into functions.php of your theme
  8.  
  9. function hierarchical_category_tree( $cat ) {
  10.     static $depth=0;    
  11.     // wpse-41548 // v1.3 // structured nested list // alchymyth // a hierarchical list of all categories //    
  12.     $next = get_categories('hide_empty=0&orderby=name&order=ASC&parent=' . $cat);    
  13.     if( $next ) :  
  14.         $depth++;    
  15.             echo "\n";  for($i=1;$i<$depth;$i++) echo '   '; //for structured html output    
  16.         echo '<ul class="depth-'.$depth.'">';  
  17.         foreach( $next as $cat ) :
  18.             echo "\n ";     for($i=1;$i<$depth;$i++) echo '   '; //for structured html output    
  19.         echo '<li><a href="' . get_category_link( $cat->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $cat->name ) . '">' . $cat->name . '</a>';    
  20.         hierarchical_category_tree( $cat->term_id );    
  21.         echo '</li>';
  22.         endforeach;
  23.             echo "\n";  for($i=1;$i<$depth;$i++) echo '   '; //for structured html output    
  24.         echo '</ul><!--/.depth-'.$depth.'-->';      
  25.         $depth--;
  26.             echo "\n ";     for($i=1;$i<$depth;$i++) echo '   '; //for structured html output      
  27.     endif;         
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement