Advertisement
alchymyth

hierachical category list with description

Apr 6th, 2011
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php  
  2. process_cat_trees();
  3.  
  4. function process_cat_trees( $cat='' ) {/*****************************************************************
  5. *
  6. * alchymyth 2011
  7. * transformationpowertools.com/wordpress
  8. * a hierarchical list of all categories, with linked post titles
  9. *
  10. ******************************************************************/
  11.  
  12.    if($cat == '') :
  13.      foreach( get_categories('hide_empty=false') as $category ) :
  14.      if( !$cat->parent ) { $next[] = $category; }
  15.      endforeach;
  16.    else:
  17.      $next = get_categories('hide_empty=false&parent=' . $cat);
  18.    endif;
  19.  
  20.  if( $next ) :
  21.  foreach( $next as $cat ) :
  22.  
  23.  if(get_category($cat)->category_description) {
  24.    $desc = '<span class="description">' . get_category($cat)->category_description . '</span>'; echo "\n"; }
  25.   else { $desc = '<span class="description">no description available</span>'; }
  26.      
  27.  echo '<ul><li><a href="' . get_category_link($cat->term_id) . '">' . $cat->name . ' ' . $desc . '</a></li>'; echo "\n";
  28.  process_cat_trees( $cat->term_id );
  29.  endforeach;
  30.  endif;
  31.  
  32.  echo '</ul>'; echo "\n";
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement