function category_menu($parent = '0') {
$CI =& get_instance();
$has_childs = FALSE; //this prevents printing 'ul' if we don't have subcategories for this category
$categories = $CI->Menu_model->category_menu();
$output = "";
//print_r($categories);
$i = 0;
foreach($categories as $key => $value) {
if ($value['parent'] == $parent) {
//if this is the first child print '<ul>'
if ($has_childs === false) {
//don't print '<ul>' multiple times
$has_childs = true;
echo "<ul id=\"child".$i."\">\n";
}
echo "<li><a href=\"/category/" . $value['name'] . "\">" . $value['name'] . "</a>";
category_menu($key);
//call function again to generate nested list for subcategories belonging to this category
echo "</li>\n";
}
$i++;
}// endforeach
if ($has_childs === true) echo "</ul>\n";
//writecategory($output);
}// category_menu