Friday, November 1, 2013

Wordpress get sub categories

Get the sub categories if the current category is a parent.

<code>
<?php $category_id2 = get_query_var('cat'); // get the category ?>
<?php         
            $child_cats=array();

            foreach(get_all_category_ids() as $cat)
            {
                if(get_category($cat)->parent==$category_id2)
                {
                    $child_cats[]=$cat;
                }
            }
            $aa = 0;
            foreach ($child_cats as $ca)
            {
                echo $child_cats[$aa].'<br />';
                $aa++;  
            }

?>
</code>


No comments:

Post a Comment