Support » Themes and Templates » List Children of Category Only On That Parent Category

  • I want to display a dynamic list of page title links when you are on a page that has sub pages. I found out that the code below works for pages.

    <script src=""></script>

    How do I get it to work for categories?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Ok, am new here. I obviously don’t get how things work.
    I guess this is the code below:

    <?php if ( is_page() ) {
          $children = wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->post_parent.'&echo=0');
          $children = wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->ID.'&echo=0');
          if ($children) {
          <div class="sidebar">
            <?php echo $children; ?>
    } // End If Post
           } // End if is page

    How can I get this to work on Categories instead of Pages?

    You’re trying to list sub-catgories on a category archive page? Try this:

    if(is_category()) :
    	$breakpoint = 0;
    	$thiscat = get_term( get_query_var('cat') , 'category' );
    	$subcategories = get_terms( 'category' , 'parent='.get_query_var('cat') );
    	if(empty($subcategories) && $thiscat->parent != 0) :
    		$subcategories = get_terms( 'category' , 'parent='.$thiscat->parent.'' );
    	if(!empty($subcategories)) :
    		foreach($subcategories as $subcat) :
    			if($thiscat->term_id == $subcat->term_id) $current = ' current-cat'; else $current = '';
    			$items .= '
    			<li class="cat-item cat-item-'.$subcat->term_id.$current.'">
    				<a href="'.get_category_link( $subcat->term_id ).'" title="'.$subcat->description.'">'.$subcat->name.'</a>
    		echo "
    		<!--START SUB CATEGORY -->
                   <div id='subcats'>
    		</div><!--/subcats--> ";

    You’ll have to style it using CSS.

    Thanks but does this work for Pages too? Am displaying the list on the siderbar.

    It might be easier if you search the plugin directory for a plugin that can create sub-menus or list sub-categories.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘List Children of Category Only On That Parent Category’ is closed to new replies.