Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Dylan Lopez
Added: Mar 5, 2018 8:39 AM
Modified: Mar 5, 2018 8:43 AM
Views: 10
Tags: bonfire helper
  1. function build_nested_menu($categories, $outstring="") {
  2.     if(empty($categories)) return $outstring;
  3.     $outstring .= '<ul> ';
  4.     foreach($categories as $cat) {
  5.         $outstring .= '<li><a href="'.$cat->url.'">'.$cat->name.'</a> ';
  6.             if(isset($cat->nodes))
  7.                 return build_nested_menu($cat->nodes, $outstring) .'</ul> ';
  8.         $outstring .= '</li> ';
  9.     }
  10.     $outstring .= '</ul> ';
  11.     return $outstring;
  12. }
  13.  
  14. // Load categories helper
  15. $this->load->helper('categories/categories');
  16.  
  17. // Loop thru all menus
  18. foreach(list_all_menus() as $menu) {
  19.     echo build_nested_menu(list_menu_categories($menu->id));
  20. }