Put this into functions.php
[php]function get_mymenu($curcat = 0, $depth = 0)
{
$breadcats = my_get_breadcats($curcat);
$my_cats = my_get_all_categories();
$html = "<ul class=\"children\">";
$categories = $my_cats[$breadcats[$depth]];
foreach ($categories as $cat)
{
$html.= "<li class=\"cat-item\"><a href=\"". get_category_link( $cat->cat_ID ) ."\">". $cat->cat_name ."</a>";
if ($cat->cat_ID == $breadcats[$depth+1] && $depth<count($breadcats))
{
$html.= get_mymenu($curcat, $depth+1);
}
$html.= "</li>\n";
}
$html.= "</ul>\n";
return $html;
}
function my_get_all_categories()
{
static $my_cats = array();
if (count($my_cats)==0)
{
$categories = get_categories(‘child_of=0’);
foreach ($categories as $cat)
{
$my_cats[$cat->category_parent][$cat->cat_ID] = $cat;
}
}
return $my_cats;
}
function my_get_breadcats($curcat = 0)
{
static $breadcats = array();
if (count($breadcats)==0)
{
$curcat = intval($curcat);
$breadcats[] = $curcat;
while($curcat!=0)
{
$curcategory = get_category($curcat);
$curcat = intval($curcategory->category_parent);
$breadcats[] = $curcat;
}
$breadcats = array_reverse($breadcats);
}
return $breadcats;
}[/php]
And this into your template
[php]<div class="block">
<h3>My menu</h3>
<?= get_mymenu($wp_query->query_vars[‘cat’]);?>
</div>[/php]
Leave a Reply