Home / category / List all Subcategories
  • How to List all Subcategories

    list-all-subcategories

    Adding this PHP code to your wordpress theme will display a list of only subcategories

    ( click code to copy )

    wordpress snippet : PHP

    <>
        $echo = '<ul>' . "\n";
        $childcats = get_categories('child_of=' . $cat . '&hide_empty=1');
        foreach ($childcats as $childcat) {
            if (1 == $childcat->category_parent) {
                $echo .= "\t" . '<li><a href="' . get_category_link($childcat->cat_ID).'" title="' . $childcat->category_description . '">';
                $echo .= $childcat->cat_name . '</a>';
                $echo .= '</li>' . "\n";
                }
        }
        $echo .= '</ul>' . "\n";
        echo $echo;
    

    ( WordPress codex functions, hooks, in this snippet. )

    category_description, category_link, get_categories, get_category, get_category_link, _n, _e,