Advertisement
alchymyth

hierarchical category list with depth

Feb 8th, 2012
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  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 // 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.         foreach( $next as $cat ) :    
  11.         echo '<ul class="depth-'.$depth.'"><li><strong>' . $cat->name . '</strong>';    
  12.         echo ' / <a href="' . get_category_link( $cat->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $cat->name ) . '" ' . '>View ( '. $cat->count . ' posts )</a>  ';      
  13.         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>';      
  14.         hierarchical_category_tree( $cat->term_id );    
  15.         endforeach;
  16.         $depth--;      
  17.     endif;    
  18.     echo '</li></ul>'; echo "\n";
  19. }  
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement