showing subcategories on WordPress category pages

show the subcategories for a given category on it’s category page .Basically you need to check whether there are any children, and if there are, list the categories with the current category as a parent or grandparent. The following code does just that:

if (is_category()) {
  $this_category = get_category($cat);
  if (get_category_children($this_category->cat_ID) != "") {
    echo "


; echo "
    "; wp_list_categories('orderby=id&show_count=0&title_li= &use_desc_for_title=1&child_of='.$this_category->cat_ID); echo "
; } }

There are no comments yet, add one below.

Leave a Comment