• I am having a little issue of repeating sub-categories for some reason. I am using this code from this old thread, but on the categories page on my site, if you scroll towards the bottom, the sub-categories are repeated, as top level categories, even though they are not. I am wanting the categories to show as they are, with the sub-categories listed underneath their parent category description, I just cannot figure out why they are repeating at the bottom.

    Here’s my entire template, in case someone can see something I have missed.

    <?php
    /* Template Name: Categories2 */
    get_header(); ?>
    
    <?php the_post(); ?>
    
    <div id="entry">
    
    <div class="entry-content">
    
    <?php
    process_cat_trees(); 
    
    function process_cat_trees( $cat='' ) {
    /*****************************************************************
    *
    * alchymyth 2011
    * transformationpowertools.com/wordpress
    * a hierarchical list of all categories, with descriptions
    *
    ******************************************************************/
    
       if($cat == '') :
    //add any parameter for get_categories() into the code in the next line//
         foreach( get_categories('hide_empty=true') as $category ) :
         if( !$cat->parent ) { $next[] = $category; }
    	 endforeach; 
    
       else:
         $next = get_categories('hide_empty=true&parent=' . $cat);
       endif;
    
     if( $next ) :
     foreach( $next as $cat ) :
    
     if(get_category($cat)->category_description) {
       $desc = get_category($cat)->category_description; }
      else { $desc = ''; } 
    
     echo '<ul><li><a href="' . get_category_link($cat->term_id) . '" title="' . sprintf( __( "View all %s videos" ), $category->name ) . '" ' . '><strong>' . $cat->name . '</strong></a><span><br />' . $desc . '</span></li>'; echo "\n";
     process_cat_trees( $cat->term_id );
     endforeach;
     endif;
    
     echo '</ul>'; echo "\n";
    }
    ?>
    
    <?php get_search_form(); ?>
    
    </div><!-- END ENTRY CONTENT -->
    </div><!-- END ENTRY -->
    </div><!-- END CONTENT -->
    
    <?php get_footer(); ?>
  • The topic ‘Showing Categories, Sub categories and descriptions’ is closed to new replies.