Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Posts
    364
    Plugin Contributions
    0

    Default 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...
    Experience is what you get when you don’t get what you want…

  2. #2
    Join Date
    Nov 2004
    Posts
    364
    Plugin Contributions
    0

    Default 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.
    Experience is what you get when you don’t get what you want…

 

 

Similar Threads

  1. v150 How to display Top Cat & Sub Cat but not Sub Sub Cats??
    By spiggles87 in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 5 Mar 2013, 06:37 PM
  2. Category images and sub cats not showing
    By lunarc in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 4 Oct 2010, 10:46 PM
  3. Can I display sub cats under their main cats without having to click on main cats?
    By Sushigal in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 11 May 2009, 11:10 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR