How to list child categories in custom category template?

This piece of code will return you the child categories of a parent-

$cat = get_category( get_query_var( 'cat' ) );
$cat_id = $cat->cat_ID;
$child_categories=get_categories(
    array( 'parent' => $cat_id )
);

Just pass the category id to $cat_id variable which children you want. After that you can design or print those as you want. Example-

foreach ( $child_categories as $child ) {
    // Here I'm showing as a list...
    echo '<li>'.$child ->cat_name.'</li>';
}

Hope this is gonna help.

Leave a Comment