Advertisement
alchymyth

cat and desc list

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