SHARE
TWEET

nested hierarchical category list

alchymyth Feb 10th, 2012 633 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php      
  2. hierarchical_category_tree( 0 ); // the function call; 0 for all categories; or cat ID
  3.  
  4. function hierarchical_category_tree( $cat ) {
  5.         static $depth=0;    
  6.         // wpse-41548 // v1.3 // structured nested list // alchymyth // a hierarchical list of all categories //    
  7.         $next = get_categories('hide_empty=0&orderby=name&order=ASC&parent=' . $cat);    
  8.         if( $next ) :  
  9.                 $depth++;    
  10.                         echo "\n";      for($i=1;$i<$depth;$i++) echo '   '; //for structured html output    
  11.                 echo '<ul class="depth-'.$depth.'">';  
  12.                 foreach( $next as $cat ) :
  13.                         echo "\n ";     for($i=1;$i<$depth;$i++) echo '   '; //for structured html output    
  14.                 echo '<li><strong>' . $cat->name . '</strong>';    
  15.                 echo ' / <a href="' . get_category_link( $cat->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $cat->name ) . '" ' . '>View ( '. $cat->count . ' posts )</a>  ';      
  16.                 echo ' / <a href="'. get_admin_url().'edit-tags.php?action=edit&taxonomy=category&tag_ID='.$cat->term_id.'&post_type=post" title="Edit Category">Edit</a>';      
  17.                 hierarchical_category_tree( $cat->term_id );    
  18.                 echo '</li>';
  19.                 endforeach;
  20.                         echo "\n";      for($i=1;$i<$depth;$i++) echo '   '; //for structured html output    
  21.                 echo '</ul><!--/.depth-'.$depth.'-->';      
  22.                 $depth--;
  23.                         echo "\n ";     for($i=1;$i<$depth;$i++) echo '   '; //for structured html output      
  24.         endif;                 
  25. }  
  26. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top