Zen Cart Logo
Forums / General Questions / Only shoe current category subcategories

Only shoe current category subcategories

Locked

Views: 3,739

Results 1 to 16 of 16
This thread is locked. New replies are disabled.
8 Jun 2007, 1:32 AM
#1
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

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.

8 Jun 2007, 2:05 AM
#2
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

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.

8 Jun 2007, 3:59 AM
#3
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

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.

8 Jun 2007, 12:01 PM
#4
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

Re: Only shoe 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

8 Jun 2007, 2:54 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Only shoe 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.

9 Jun 2007, 12:34 AM
#6
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

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.

12 Jun 2007, 6:50 AM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Only shoe current category subcategories

In /includes/templates/your_template/sideboxes/tpl_categories.php, find php for ($i=0;$i<sizeof($box_categories_array);$i++) { switch(true) { and replace with ```php
$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) {

```php
    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 {
``` and replace with ```php
    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 {
13 Jun 2007, 12:58 AM
#8
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

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.

<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license [URL]http://www.zen-cart.com/license/2_0.txt[/URL] 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>';
?>
13 Jun 2007, 1:59 AM
#9
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

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?

13 Jun 2007, 3:50 AM
#11
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Only shoe current category subcategories

I believe it is working as designed; but since you have structured your categories with everything under the NFL top cat, that is always the active top cat and everything under it shows.
What you actually want is for the active first level subcat to determine what shows. That is possible, but will require some more detailed coding, and some special conditions applied to the display.

13 Jun 2007, 4:02 AM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Only shoe current category subcategories

A little further investigation shows that it really is working as designed. Clicking on Specials reveals the menu with all the top cats; though there is no content for the others. THat makes getting the active subcat to show more complicated.

12 Apr 2009, 8:16 PM
#13
helensama avatar

helensama

New Zenner

Join Date:
Dec 2006
Location:
Northwest Connecticut
Posts:
87
Plugin Contributions:
0

Re: Only shoe current category subcategories

I made these code changes in tpl_categories.php and they work....here is the site I am working on - http://peterfasano.com/zen/

I thought this was exactly what I need to do, but I am noticing something that means additional or other changes --- I am noticing that when you get to the sub category and product level the subcategories for the current category don't appear anymore and I'd like them to....

As an example with this site in particular, click on Fabrics, you see the subcategories for Fabrics only appear in the left hand column side box, but as soon as you click on a subcategory, i.e. drill down, nothing appears. Is it possible to modify this code even further to make the subcategories for the current category remain even while drilling down to product level?

What I am ultimately looking for is ---- for example -- in the Fabrics category have the four Fabrics subcategories in the sidebox, no Categories heading, no All Products, no New Products, no dividing hr line. Also, I am looking at how to highlight the current subcatgeory you are in, so if you were looking at something in Prints, under Fabrics, Prints would be highlighted.

Maybe this can all or partly be accomplished using css?

If this is already documented someplace and you can point me to it, great! Or if you have some additional coding suggestions for doing this, great! Especially thanks to Glenn for posting these and some other coding changes that have been really helpful!

14 Apr 2009, 9:14 AM
#14
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Only shoe current category subcategories

You might try Categories Dressing, which has this display ability built in.
In categories_dressing_defines.php:

//display only the active top category and its subs, hide top cats, hide sub-subcats, or any combination.
//only uncomment and set this define if you want to hide cats based on active tree or level
// 'active|highest_level|deepest_level'
//active: 0=all tops/1=active tree only/2=active only (all tops when no cat selected)/3=full active tree, others limited per level controls|
//highest_level:0=all levels/1=no topcats/etc.|
//deepest_level: 1=only first subcats/2=first & second subcats/etc.
//
define('CAT_BOX_ACTIVE_LEVEL', '3|1|9');

suppressing the top current cat may take a bit of code added. I'll dig it up for you if you want.

The highlighting is done (in Cat Dressing) with #categories li a.cat-parent-text and
#categories li a.cat-selected-text .

14 Apr 2009, 9:23 AM
#15
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Only shoe current category subcategories

  • Actually, the top cat suppression can be done in the stylesheet. Change

#categories ul a {/top categories/
display: list-item;

to

#categories ul a {/top categories/
display: none;

14 Apr 2009, 12:25 PM
#16
helensama avatar

helensama

New Zenner

Join Date:
Dec 2006
Location:
Northwest Connecticut
Posts:
87
Plugin Contributions:
0

Re: Only shoe current category subcategories

I got the top category to not display by adding this to the stylesheet .category-top {display:none;} but am still searching and need a way to have the sub categories continue to display even if you are aat the product level.... I don't know why they are disappearing?