Ready to get started?Download WordPress


List Children of Category Only On That Parent Category (5 posts)

  1. azukah
    Posted 3 years ago #

    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="http://pastebin.com/embed_js.php?i=CuQuLsua"></script>

    How do I get it to work for categories?

  2. azukah
    Posted 3 years ago #

    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?

  3. Michelle Langston
    Theme Wrangler at Automattic
    Posted 3 years ago #

    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.

  4. azukah
    Posted 3 years ago #

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

  5. Michelle Langston
    Theme Wrangler at Automattic
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic