Zen Cart Logo

Hide single category tab

Views: 4,245

Results 1 to 14 of 14
7 Nov 2012, 9:50 PM
#1
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Hide single category tab

Hi I need to hide a single category tab from the categories tabs menu in the header, but not anywhere else.

I gathered that if I could create a separate style for each category tab then I would be able to just hide the category tab I don't want visible with CSS using display:none;

So the categories would be like this

category 1 = style1

category 2 = style2

category 3 = style3

So if I wanted to his category 3 I would do something like this

#navCatTabs .style3 {
display:none;
}

Or if you want to look at it in zen code

#navCatTabs .category-top3 {
display:none;
}

So I need some way of creating a separate style for each tab. This would simply mean adding a number onto the end of 'category-top' in order.

so the tabs would be .category-top1, .category-top2, .category-top3 etc in order. The number could probably be pulled from the sort order number.

How would I go about this?

Thanks

Nick

8 Nov 2012, 5:05 PM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: Hide single category tab

You could do exactly what you asked with an edit to one line in tpl_modules_categories_tabs.php, but that would fail if you added or removed a top category that displays to the left of your hidden category.
For a better method that will hide the specific category, not the position, find this in
/includes/modules/your_template/categories_tabs.php

  // currently selected category
  if ((int)$cPath == $categories_tab->fields['categories_id']) {
    $new_style = 'category-top';
    $categories_tab_current = '<span class="category-subs-selected">' . $categories_tab->fields['categories_name'] . '</span>';
  } else {
    $new_style = 'category-top';
    $categories_tab_current = $categories_tab->fields['categories_name'];
  }
```Change the two lines```php
    $new_style = 'category-top';

to```php
$new_style = 'category-top cat' . $categories_tab->fields['categories_id'];

Now you can address each link individually like .cat23 {display: none;}

If your cat-tabs bar has tab styling that involves the <li> element, you will need to hide the whole tab, not just the link. Find in 
/includes/templates/your_template/templates/tpl_modules_categories_tabs.php```php
  <li><?php echo $links_list[$i];?></li>

Change to```php

<li class="<?php echo substr($links_list[$i], 23, (strpos('" hr', $links_list[$i]) - 23));?>"><?php echo $links_list[$i];?></li> ``` If there are any issues with this, let me see the site and I can adjust the substr/strpos details.
8 Nov 2012, 5:17 PM
#3
gjh42 avatar

gjh42

Black Belt

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

Re: Hide single category tab

You could also do a brute-force CSS solution, which would hide only the given tab position, not a specific category, but would not require editing any PHP files.
To hide only the third tab:

#navCatTabs li+li+li {display: none;}
#navCatTabs li+li+li+li {display: inline;}

You have to explicitly set the fourth and following tabs back to whatever display status they were.

8 Nov 2012, 5:42 PM
#4
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Hide single category tab

Hi Glenn, I opted for the PHP option as it suits me better and I think works better overall.

This line

$new_style = 'category-top cat' . $categories_tab->fields['categories_id'];

works a treat, however

This line

<li class="<?php echo substr($links_list[$i], 23, (strpos('" hr', $links_list[$i]) - 23));?>"><?php echo $links_list[$i];?></li>

breaks the cPath links and throws up errors.

Instead of cPath you get code like the following

<ul> <li class="cat2" href="http://WEBSITE.com/index.php?main_page=index&cPath=2">C"><a class="category-top cat2" href="http://WEBSITE.com/index.php?main_page=index&cPath=2">Chesterfield Suites</a> </li> <li class="cat1" href="http://WEBSITE.com/index.php?main_page=index&cPath=1"><span class="category-subs-selected">Chester"><a class="category-top cat1" href="http://WEBSITE.com/index.php?main_page=index&cPath=1"><span class="category-subs-selected">Chesterfield Sofas</span></a> </li> <li class="cat3" href="http://WEBSITE.com/index.php?main_page=index&cP"><a class="category-top cat3" href="http://WEBSITE.com/index.php?main_page=index&cPath=3">Club Chairs</a> </li> <li class="cat4" href="http://WEBSITE.com/index.php?main_page=index&cPath="><a class="category-top cat4" href="http://WEBSITE.com/index.php?main_page=index&cPath=4">Wingback Chairs</a> </li> <li class="cat5" href="http://WEBSITE.com/index.php?main_page=index&cPath=5">Fo"><a class="category-top cat5" href="http://WEBSITE.com/index.php?main_page=index&cPath=5">Footstools and Boxes</a> </li> <li class="cat6" href="http://WEBSITE.com/index.php?main_page=index&cPa"><a class="category-top cat6" href="http://WEBSITE.com/index.php?main_page=index&cPath=6">Study Chairs</a> </li> <li class="cat7" href="http://WEBSITE.com/index.php?main_page=index&cPath=7">"><a class="category-top cat7" href="http://WEBSITE.com/index.php?main_page=index&cPath=7">Used Chesterfields</a> </li> <li class="cat8" href="http://WEBSITE.com/index.php?main_page=index&cPa"><a class="category-top cat8" href="http://WEBSITE.com/index.php?main_page=index&cPath=8">Leather Care</a> </li> </ul>

If the above can be fixed then I think its worthy of a small mod since I'm not the only one looking for a solution to this.

Thanks very much so far, just needs the above fixing.

8 Nov 2012, 6:09 PM
#5
gjh42 avatar

gjh42

Black Belt

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

Re: Hide single category tab

Oops, I left out part of the strpos() syntax. This line```php

<li class="<?php echo substr($links_list[$i], 23, (strpos('" hr', $links_list[$i]) - 23));?>"><?php echo $links_list[$i];?></li> ``` should be```php <li class="<?php echo substr($links_list[$i], 23, (strpos($links_list[$i], '" hr', $links_list[$i]) - 23));?>"><?php echo $links_list[$i];?></li> ```
8 Nov 2012, 7:40 PM
#6
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Hide single category tab

Fantastic Glenn, thanks very much indeed. This will save me loads of time.

Are you going to package this up into a mod? Seems such a basic thing, but one that doesn't ever seem to have been solved before so I think its definitely worth a mod.

17 Nov 2012, 8:31 PM
#7
gjh42 avatar

gjh42

Black Belt

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

Re: Hide single category tab

I have packaged up a mod, and would appreciate people trying it before I submit it to Plugins. Please post your experience here if you install it.
[Attachment no longer available]

18 Nov 2012, 5:29 AM
#8
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Hide single category tab

gjh42:

I have packaged up a mod, and would appreciate people trying it before I submit it to Plugins. Please post your experience here if you install it.
[Attachment no longer available]

This mod works well on Zen Cart v1.5.1. Its only 2 files is very easy to use and install, and did not conflict with any of my other 10 modules currently installed. I wish all mods were this simple. Oh yeah, if you are running the companion module (Category Dressing) for another styling the side menu, these will both work hand in hand. Instructions were very clear. Thank you so much!

20 Nov 2012, 11:10 AM
#9
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Hide single category tab

Yes thanks for this, very simple but one of those things that seems to have previously been overlooked. This opens up plenty of ways to CSS category tabs as well as hiding them.

20 Nov 2012, 4:17 PM
#10
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Hide single category tab

Glenn, here's another one which would be handy and probably require something similar written.

Currently I have some modified code which adds an body id to each category

so you get <body id="category1">

What would be really cool is if we were also able to control the display of certain elements on each product page using body class as well as ID.

So you would have something like this <body id="category1" class="my-amazing-product">, where my-amazing-product is the product name which would normally be My Amazing Product with uppercase letters and lowercase letters and without dashes in between.

In short, when you name a product called My Amazing Product in the admin is adds a class to the product info page called my-amazing-product

20 Nov 2012, 6:27 PM
#11
gjh42 avatar

gjh42

Black Belt

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

Re: Hide single category tab

Smart Backgrounds from Plugins does a version of that already. You can also use per-product stylesheets by making a file named like p_256.css (using the product id) and saving in /includes/templates/your_template/css/. Any rules in that will apply only to that product's info page. See /includes/templates/template_default/css/CSSreadme.txt for related info.

21 Nov 2012, 10:59 AM
#12
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Hide single category tab

gjh42:

Smart Backgrounds from Plugins does a version of that already. You can also use per-product stylesheets by making a file named like p_256.css (using the product id) and saving in /includes/templates/your_template/css/. Any rules in that will apply only to that product's info page. See /includes/templates/template_default/css/CSSreadme.txt for related info.

Ok thanks for this.

14 Aug 2013, 5:44 AM
#13
smcelligott avatar

smcelligott

New Zenner

Join Date:
Nov 2009
Location:
Sydney Australia
Posts:
84
Plugin Contributions:
0

Re: Hide single category tab

gjh42:

I have packaged up a mod, and would appreciate people trying it before I submit it to Plugins. Please post your experience here if you install it.
[Attachment no longer available]

This sounds like exactly what I need, but when I tried to download the attachment, I got an error, "Invalid Attachment specified. If you followed a valid link, please notify the administrator."

Am I doing something wrong?

14 Aug 2013, 5:58 PM
#14
gjh42 avatar

gjh42

Black Belt

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

Re: Hide single category tab

The mod is now available from Plugins as Categories-Tabs Dressing.