Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Join Date
    May 2007
    Posts
    213
    Plugin Contributions
    0

    Default Only shoe current category subcategories

    Hi all.... Is it possible to modify Zen Cart so that it will only show the subcategories for the current category you are in at the left?

    For example... Say I have 5 main categories when my site load - Cat 1, Cat 2, Cat 3, Cat 4 and Cat 5.

    Under Cat 1 I have sub categories A, B, C and D and under sub category I have E, F, G and H.

    Ok, now when someone visits and clicks on Category 1 I only want to show them A, B, C and D on the left. I am not worried about them getting lost because I also have a nav at the top with drop downs so they can easily navigate. I have like 30+ categories though and my page is so long for no reason.

    Thanks in advance.

  2. #2
    Join Date
    May 2007
    Posts
    213
    Plugin Contributions
    0

    Default Re: Only shoe current category subcategories

    I killed that above... I meant to say...

    Under Cat 1 I have sub categories A, B, C and D and under Category 2 I have sub category E, F, G and H.

  3. #3
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Only shoe current category subcategories

    You could use some of the logic developed in the Parent Categories Separated in 3 Sideboxes thread to accomplish this.

    That checks whether the category is in a list of cats to display; you could check if there is an active category (i.e. $cPath != 0) and, if so, whether the top category being looked at in the sequence is active. Save the id of the active top cat, and on the following iterations check if the cats are subs of that top cat (i.e. start with [$active_top_cat_id]_).

    This logic will display the full top cat menu on every page except when a cat has been clicked and you are viewing a particular cat and its subs.

  4. #4
    Join Date
    May 2007
    Posts
    213
    Plugin Contributions
    0

    Default Re: Only show current category subcategories

    Glenn,

    Thanks for responding... Can you offer more guidance as I am new to Zen and PHP. You have been so helpful with some of my other requests and I appreciate it greatly.

    I read the other post and I am still a bit confused on where I need to start and what I need to change to give this a whirl.

    Thanks

  5. #5
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Only show current category subcategories

    I'll be happy to help, though I am likely to be away much of the time until Sunday night. If anyone else has ideas feel free to jump in.

    If this works as I am envisioning, it will be a compact snippet of code and should be easy to drop in.

  6. #6
    Join Date
    May 2007
    Posts
    213
    Plugin Contributions
    0

    Default Re: Only shoe current category subcategories

    Thanks Glenn... I look forward to hearing from you, or anyone else for that matter that may be able to assist me.

  7. #7
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Only shoe current category subcategories

    In /includes/templates/your_template/sideboxes/tpl_categories.php, find
    PHP Code:
      for ($i=0;$i<sizeof($box_categories_array);$i++) {
        switch(
    true) { 
    and replace with
    PHP Code:
      $current_top 0;//show active cat tree - initialize - above for loop
      
    $iteration_top 0;//show active cat tree - initialize - above for loop
      
    for ($i=0;$i<sizeof($box_categories_array);$i++) {
        switch(
    true) { 
    Find
    PHP Code:
        if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) { 
          
    // skip if this is for the document box (==3)
        
    } else { 
    and replace with
    PHP Code:
        if ($box_categories_array[$i]['current'] and $box_categories_array[$i]['top'] == 'true') {  //show active cat tree - if current and topcat
          
    $current_top str_replace("cPath=","",$box_categories_array[$i]['path']); //show active cat tree - set = current topcat
        
    //show active cat tree 
        
    $iteration_top str_replace("cPath=","",str_replace(strchr($box_categories_array[$i]['path'],"_"),"",$box_categories_array[$i]['path'])); //show active cat tree - set = this iteration's topcat
        
    if (($current_top != $iteration_top and isset($cPath) and $cPath != 0) or (zen_get_product_types_to_category($box_categories_array[$i]['path']) == or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1))) {
          
    // skip if this is for the document box (==3) OR (show active cat tree) if not in/under current topcat and there is a selected cat
        
    } else { 

  8. #8
    Join Date
    May 2007
    Posts
    213
    Plugin Contributions
    0

    Default Re: Only shoe current category subcategories

    It didn't seem to make any difference... Here is the code, did I type something wrong. I commented with my initials SPD. Thanks for helping.

    Code:
    <?php
    /**
     * Side Box Template
     *
     * @package templateSystem
     * @copyright Copyright 2003-2006 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: tpl_categories.php 4162 2006-08-17 03:55:02Z ajeh $
     */
      $content = "";
     
      $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
      //$content .= '<ul>';
      // SPD COMMENTED OUT for ($i=0;$i<sizeof($box_categories_array);$i++) {
      // SPD COMMENTED OUT  switch(true) {
      // SPD ADDITION SINCE COMMENTED OUT ABOVE
      $current_top = 0; //show active cat tree - initialize - above for loop 
      $iteration_top = 0; //show active cat tree - initialize - above for loop 
      for ($i=0;$i<sizeof($box_categories_array);$i++) { 
        switch(true) {
      //SPD END ADDITION
    // to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
    // uncomment the select below and set the cPath=3 to the cPath= your_categories_id
    // many variations of this can be done
    //      case ($box_categories_array[$i]['path'] == 'cPath=3'):
    //        $new_style = 'category-holiday';
    //        break;
          case ($box_categories_array[$i]['top'] == 'true'):
            $new_style = 'category-top';
            break;
          case ($box_categories_array[$i]['has_sub_cat']):
            $new_style = 'category-subs';
            break;
          default:
            $new_style = 'category-products';
          }
      // SPD COMMENTED OUT 
         //if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
         //   // skip if this is for the document box (==3)
         //} else {
      // SPD END COMMENT OUT
     
      // SPD ADDITION SINCE I COMMENTED OUT SECTION ABOVE
      if ($box_categories_array[$i]['current'] and $box_categories_array[$i]['top'] == 'true') {  //show active cat tree - if current and topcat 
           $current_top = str_replace("cPath=","",$box_categories_array[$i]['path']); //show active cat tree - set = current topcat 
         } //show active cat tree  
         $iteration_top = str_replace("cPath=","",str_replace(strchr($box_categories_array[$i]['path'],"_"),"",$box_categories_array[$i]['path'])); //show active cat tree - set = this iteration's topcat 
         if (($current_top != $iteration_top and isset($cPath) and $cPath != 0) or (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1))) { 
           // skip if this is for the document box (==3) OR (show active cat tree) if not in/under current topcat and there is a selected cat 
         } else {  
      // SPD END ADDITION
     
         // $content .= '<li>';
          $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
          if ($box_categories_array[$i]['current']) {
            if ($box_categories_array[$i]['has_sub_cat']) {
              $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
            } else {
              $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
            }
          } else {
            $content .= $box_categories_array[$i]['name'];
          }
          if ($box_categories_array[$i]['has_sub_cat']) {
            $content .= CATEGORIES_SEPARATOR;
          }
          if (SHOW_COUNTS == 'true') {
            if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
              $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
            }
          }
          $content .= '</a>';
     
          //$content .= '</li>';
          //$content .= '<br />' . "\n";
        }
     
      }
      //$content .= '</ul>';
      if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true' or SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
    // display a separator between categories and links
        if (SHOW_CATEGORIES_SEPARATOR_LINK == '1') {
          $content .= '<hr id="catBoxDivider" />' . "\n";
        }
        //$content .= '<ul>';
     
        if (SHOW_CATEGORIES_BOX_SPECIALS == 'true') {
          $show_this = $db->Execute("select s.products_id from " . TABLE_SPECIALS . " s where s.status= 1 limit 1");
          if ($show_this->RecordCount() > 0) {
            //$content .= '<li>';
            $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_SPECIALS) . '">' . CATEGORIES_BOX_HEADING_SPECIALS . '</a>' . "\n";
            //$content .= '</li>';
          }
        }
        if (SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') {
          // display limits
    //      $display_limit = zen_get_products_new_timelimit();
          $display_limit = zen_get_new_date_range();
          $show_this = $db->Execute("select p.products_id
                                     from " . TABLE_PRODUCTS . " p
                                     where p.products_status = 1 " . $display_limit . " limit 1");
          if ($show_this->RecordCount() > 0) {
            //$content .= '<li>';
            $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_NEW) . '">' . CATEGORIES_BOX_HEADING_WHATS_NEW . '</a>' . "\n";
            //$content .= '</li>';
          }
        }
        if (SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true') {
          $show_this = $db->Execute("select products_id from " . TABLE_FEATURED . " where status= 1 limit 1");
          if ($show_this->RecordCount() > 0) {
            //$content .= '<li>';
            $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' . CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS . '</a>' . "\n";
            //$content .= '</li>';
          }
        }
        if (SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
          //$content .= '<li>';
          $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_ALL) . '">' . CATEGORIES_BOX_HEADING_PRODUCTS_ALL . '</a>' . "\n";
          //$content .= '</li>';
        }
        //$content .= '</ul>';
      }
     
      $content .= '</div>';
    ?>

  9. #9
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Only shoe current category subcategories

    It worked when I tested it... and I can't see any differences in your entry of the code.

    Do you get any effect under any circumstances? Can you post a URL?

  10. #10
    Join Date
    May 2007
    Posts
    213
    Plugin Contributions
    0

    Default Re: Only shoe current category subcategories

    http://74.52.136.194/~onlinefa/store...&products_id=3

    I just want the Arizona Cardinals and Auto Accessories to show. None of the other children under the NFL Category. Does that make sense?

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v139h HOW TO Show only current category in categories sidebox?
    By obrien48 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 30 Jan 2012, 04:45 AM
  2. Shoe Shop, different shoe sizes?
    By optimalwebsite in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 19 Feb 2009, 10:45 AM
  3. Replies: 2
    Last Post: 30 Jul 2008, 08:35 AM
  4. Can I Display Specials only for current category?
    By paperthreads in forum Setting Up Specials and SaleMaker
    Replies: 4
    Last Post: 12 Apr 2008, 10:30 PM
  5. Displaying only the current category in New Products
    By pleitch in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 27 Apr 2007, 04:33 AM

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