How to build category tree including sub-cats
Greetings,
I'm working on coding a new Bootstrap 4 Header nav bar, incorporating the Smartmenus for Bootstrap plugin, and wish to create a categories dropdown menu, including all sub-cats.
I would like to leverage existing ZC 1.5.7b classes/functions for generating a category tree array that I can loop through and style with the Bootstrap/Smartmenus css classes.
I've been looking at the category_tree class and some of the code within the categories sidebox, but my limited understanding of how to use the category_tree class, I can only seem to get an array with just top level cats. See my test code snippet below.
PHP Code:
$main_category_tree = new category_tree;
$box_categories_array = array();
// don't build a tree when no categories
$check_categories = $db->Execute("select categories_id from " . TABLE_CATEGORIES . " where categories_status=1 limit 1");
if ($check_categories->RecordCount() > 0) {
$box_categories_array = $main_category_tree->zen_category_tree();
}
for ($i = 0, $j = count($box_categories_array); $i < $j; $i++) {
echo $box_categories_array[$i]['name'].' => is top: '.$box_categories_array[$i]['top'].' => has sub: '.$box_categories_array[$i]['has_sub_cat'].'<br>';
}
Would using the zen_categories_ul_generator class be a better start and just str_replace in my css classes?
Any help with this would be much appreciated!
Thanks...
Re: How to build category tree including sub-cats
OK, seemed to answer my own question. Going with code from the tpl_modules_mobile_menu.php file which uses the zen_categories_ul_generator class. This gives me the complete cat tree, now just need to do some str_replace to work in the Bootstrap css classes.
Side note: If you haven't looked at the Smartmenus plugin for Bootstrap, it's real slick. Handles dropdown on hover for PC, can create simple mega menus, and it separates the Bootstrap menu trigger code so you can link the dropdown menu name to a URL.