Results 1 to 9 of 9
  1. #1
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default code to display subcategories

    1.5.7c
    Bootstrap clone

    How would I expand the code below to display also the subcategories in the corresponding top category div?
    Possibly with their own div.

    Thank you

    PHP Code:
    <div class="row row-cols-3">
    <?php
    $categories_tab 
    $db->Execute(
        
    "SELECT c.categories_id, cd.categories_name 
           FROM " 
    TABLE_CATEGORIES " c 
                INNER JOIN " 
    TABLE_CATEGORIES_DESCRIPTION " cd
                    ON cd.categories_id = c.categories_id 
                   AND cd.language_id = " 
    . (int)$_SESSION['languages_id'] . "
          WHERE c.categories_status = 1
            AND c.parent_id = 0
          ORDER BY c.sort_order, cd.categories_name"
    );

    foreach (
    $categories_tab as $category_tab) {
        
    $cat_tab_link zen_href_link(FILENAME_DEFAULT'cPath=' $category_tab['categories_id']);
        
    $cat_tab_name htmlspecialchars($category_tab['categories_name'], ENT_COMPATCHARSETtrue);
        if (isset(
    $cPath) && ((int)$cPath == $category_tab['categories_id'])) {
            
    $cat_tab_name '<span class="category-subs-selected">' $cat_tab_name '</span>';
        }
    ?>
        <div class="col"><a class="" href="<?php echo $cat_tab_link?>"><?php echo $cat_tab_name?></a></div>
    <?php
    }
    ?>
    </div>

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,474
    Plugin Contributions
    88

    Default Re: code to display subcategories

    Where will this information be displayed? On all pages?

    If it's to be displayed on selective (and non-site_map pages, since otherwise there will be a conflict since the site_map.php class will already be loaded), you could make use of the /includes/classes/site_map.php functionality. That class' constructor recursively creates an array keyed on the parent-category's id which, itself, contains an array of direct 'child' categories for that parent.

    The top-level category is categories_id 0, so you'll loop through those associated sub-categories for to gather the 1st-level children for the display.

  3. #3
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: code to display subcategories

    I did look at the site_map.
    First it is on a single page (new page added - like the page_2/3/4), and want only the categories, and their subs, no other stuff, i.e. list of other pages, ez-pages, info, etc.
    Second, when looked at the site_map class, and the zca_site_map I tried playing with the <ul> and <li>, but could not figure it out.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,474
    Plugin Contributions
    88

    Default Re: code to display subcategories

    Quote Originally Posted by keneso View Post
    I did look at the site_map.
    First it is on a single page (new page added - like the page_2/3/4), and want only the categories, and their subs, no other stuff, i.e. list of other pages, ez-pages, info, etc.
    Second, when looked at the site_map class, and the zca_site_map I tried playing with the <ul> and <li>, but could not figure it out.
    How are you looking to structure the category structure? I'll be happy to supply some basic coding, but I'm still unclear as to how you want that information displayed.

  5. #5
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: code to display subcategories

    Thank you.

    I hope I understand correctly the structure of category structure, meaning the output layout?
    If so, here is what I'd like to have, in case please help me understand your question about it.

    PHP Code:
    <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 fz-cat">
        <
    div class="col fz-top">
        <
    h3>Top category 1</h3>
            <
    div class="fz-sub-wrap">
                <
    div>sub-category 1-1</div>
                <
    div>sub-category 1-2</div>
                <
    div>sub-category 1-3</div>
            </
    div>
        </
    div>
        <
    div class="col fz-top">
        <
    h3>Top category 2</h3>
            <
    div class="fz-sub-wrap">
                <
    div>sub-category 2-1</div>
                <
    div>sub-category 2-2</div>
                <
    div>sub-category 2-3</div>
                <
    div>sub-category 2-4</div>
            </
    div>
        </
    div>
        <
    div class="col fz-top">
        <
    h3>Top category 3</h3>
            <
    div class="fz-sub-wrap">
                <
    div>sub-category 3-1</div>
            </
    div>
        </
    div>
        <
    div class="col">
        <
    h3>Top category 4</h3>
            <
    div class="fz-sub-wrap">
                <
    div>No sub</div>
            </
    div>
        </
    div>
    </
    div

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,474
    Plugin Contributions
    88

    Default Re: code to display subcategories

    Here you go:
    Code:
    <?php
    require DIR_WS_CLASSES . 'site_map.php';
    $zen_SiteMapTree = new zen_SiteMapTree;
    ?>
    <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 fz-cat">
    <?php
    foreach ($zen_SiteMapTree->data[0] as $categories_id => $cat_info) {
    ?>
        <div class="col fz-top">
        <h3><a href="<?php echo zen_href_link(FILENAME_INDEX, 'cPath=' . $categories_id); ?>"><?php echo zen_output_string_protected($cat_info['name']); ?></a></h3>
    <?php
        if (isset($zen_SiteMapTree->data[$categories_id])) {
    ?>
            <div class="fz-sub-wrap">
    <?php
            foreach ($zen_SiteMapTree->data[$categories_id] as $subcat_id => $subcat_info) {
    ?>
                <div><a href="<?php echo zen_href_link(FILENAME_INDEX, 'cPath=' . $categories_id . '_' . $subcat_id); ?>"><?php echo zen_output_string_protected($subcat_info['name']); ?></a></div>
    <?php
            }
    ?>
            </div>
    <?php
        }
    ?>
        </div>
    <?php
    }
    ?>
    </div>

  7. #7
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: code to display subcategories

    Thank you, greatly appreciated.
    Display as expected (no doubts).

    One issue if you please:
    The FILENAME_INDEX is added to the cPath making the link go to:
    /index.php?main_page=FILENAME_INDEX&cPath=14
    thus a 404

  8. #8
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,474
    Plugin Contributions
    88

    Default Re: code to display subcategories

    Quote Originally Posted by keneso View Post
    Thank you, greatly appreciated.
    Display as expected (no doubts).

    One issue if you please:
    The FILENAME_INDEX is added to the cPath making the link go to:
    /index.php?main_page=FILENAME_INDEX&cPath=14
    thus a 404
    My bad; that should be FILENAME_DEFAULT.

  9. #9
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: code to display subcategories

    Edit:
    You are too fast ;)

    Nevermind

    I changed FILENAME_INDEX to FILENAME_DEFAULT and it redirects correctly.

    Thank you

 

 

Similar Threads

  1. display subcategories
    By citiva in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 21 Mar 2012, 11:45 PM
  2. display subcategories
    By citiva in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 20 Mar 2012, 11:29 AM
  3. SubCategories Page Code ?
    By TinaS in forum Templates, Stylesheets, Page Layout
    Replies: 13
    Last Post: 11 Oct 2006, 04:34 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