If this is your first visit, check our documentation. To post, register or login.
Forums / Community Contributed Add-Ons / Addon Sideboxes / Twitch Hide Any Category

Twitch Hide Any Category

Started by twitchtoo on 1 Feb 2012, 8:08 PM · Views: 3,722

Results 1 to 10 of 10
1 Feb 2012, 8:08 PM
#1
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Post #1 by twitchtoo

Twitch Hide Any Category v1.0

Completed Feb 1st 2012 tested on ZenCart version 1.39h

This modification will allow you to hide any category you specify in includes/templates/YOUR_TEMPLATE/sideboxes/tpl_categories.php.

Simply replace/add in the code below to manually hide categories.

How it works:
As the sidebox php loop runs it simply outputs <basic html tags along with> <your category title> creating the sidebox with the many categories you see.

This code will 'empty' the $content variable for the specific category you choose before it gets wrapped in html code. It's a very simple output filter.

Any category can be removed regardless of it's hierarchy.

I have tested it on a ZenCart 1.39h with multisite, wholesale, dual pricing and a host of other custom mods without any complications.

**• Step 1

**Change this:

 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 {
  $content .= '<li><div class="betterCategories"><a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
  if ($box_categories_array[$i]['current']) {

To this:
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 {

  //Twitch Hide Any Category Step 1 of 2 - Jan 31 2012 starts
  if ($box_categories_array[$i] ['path'] == 'cPath=3_10') {
  //this line filters out the cPath=CategoryYouWantToHide 
  $content .= '';
    //this line clears the line data so it will NOT be inserted into the sidebox
  } else {
  //repeat 5 lines above to remove another category you MUST ADD AN END BRACKET below
  if ($box_categories_array[$i] ['path'] == 'cPath=3_7') {
  //this line filters out the cPath=CategoryYouWantToHide 
  $content .= '';
    //this line clears the line data so it will NOT be inserted into the sidebox
  } else {
  //repeat 5 lines above to remove another category you MUST ADD AN END BRACKET below
  //Twitch Hide Any Category Step 1 of 2 - Jan 31 2012 ends
  
  $content .= '<li><div class="betterCategories"><a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
  if ($box_categories_array[$i]['current']) {

**
• Step 2

Change this:**
$content .= '</div></li>' . "\n";
//$content .= '<br />' . "\n";
}
}

To this:

  $content .= '</div></li>' . "\n";
  //$content .= '<br />' . "\n";
}

}
//Twitch Hide Any Category Step 2 of 2 - Jan 31 2012 starts
//IMPORTANT - For each category you remove add one end bracket below
}}
//Twitch Hide Any Category Step 2 of 2 - Jan 31 2012 ends

• That's It!

You will notice it is setup to remove 2 categories - 3_10 and 3_7 - which are not in any numeric order. Just add another 5 lines of code in step 1 along with the end bracket in step 2 if you want to hide another category.

Feel free to report your findings and uses of this code in this thread!

Twitch.

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

1 Feb 2012, 10:11 PM
#2
gjh42 avatar

gjh42

Black Belt

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

Post #2 by gjh42

Note: since tpl_categories.php has not changed in a long time, this will work on any version from before v1.3.7 to v1.5.0.

Your example is customized to run on a betterCategories tpl_categories.php file, which is quite different in this area from a stock file.

$content .= '';
//this line clears the line data so it will NOT be inserted into the sidebox.= '' does not clear anything; for that you would want = ''.

2 Feb 2012, 5:19 PM
#3
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Post #3 by twitchtoo

gjh42:

Note: since tpl_categories.php has not changed in a long time, this will work on any version from before v1.3.7 to v1.5.0.

Your example is customized to run on a betterCategories tpl_categories.php file, which is quite different in this area from a stock file.

.= '' does not clear anything; for that you would want = ''.

Failing to include the period before the equal sign will break the sidebox code. It is necessary in this version of the file.

I will upload the stock code for ZenCart 1.50 after testing later today.

Twitch.

Twitch.
https://www.twitchtoo.com Do you work for free? Please donate.
June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

2 Feb 2012, 7:08 PM
#4
gjh42 avatar

gjh42

Black Belt

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

Post #4 by gjh42

If $content already holds prior item output, then you would obviously not want to clear it; but .= '' will do absolutely nothing and I don't see the point of including it.

Anyway, this concept is a good option to make available for people. Thanks for presenting it.

2 Feb 2012, 7:29 PM
#5
gjh42 avatar

gjh42

Black Belt

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

Post #5 by gjh42

Looking closer at your code, you have a series of new nested if() { }else{ }statements. This is an inefficient method which could be streamlined by simply using one
if() {
}elseif(){
}elseif(){
}else{
}
statement, which would not require keeping track of numbers of nested } at the bottom. Only one new } would be needed.

Better yet would be to put the list of excluded cPaths in one place, requiring nothing more than adding a number to include a new cPath in the list. Something like this ```php
if (in_array(str_replace('cPath=','',$box_categories_array[$i] ['path']), explode(',', '3_10,3_7,5_23,9')) {
//do nothing
}else{
//the standard code
}

26 Mar 2013, 12:13 AM
#6
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Post #6 by kevin205

So Glen what is the proper way to implement this in Zen 1.5.1?

I have created the Gift Certificate under it's own category, and I do not want it to show it in the left box. I would manually add the path to the product **Category **where I want it to appear on the site pages.

Is there a better more proper way to achieve this.

Using Zen Cart 1.5.1

26 Mar 2013, 2:49 AM
#7
gjh42 avatar

gjh42

Black Belt

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

Post #7 by gjh42

Using the stock tpl_categories.php as a base:

     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 {
      $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
``` add this to the if() test```php
or (in_array(str_replace('cPath=','',$box_categories_array[$i] ['path']), explode(',', '3_10,3_7,5_23,9'))/*hidden categories*/

to get

     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) or (in_array(str_replace('cPath=','',$box_categories_array[$i] ['path']), explode(',', '3_10,3_7,5_23,9'))/*hidden categories*/) {
        // skip if this is for the document box (==3)
      } else {
      $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';

This is all you need to do to hide categories 3_10, 3_7, 5_23 and 9 in the categories sidebox. Adjust the list as desired. You may also want to hide it in other places, which would be another job entirely..

26 Mar 2013, 3:14 AM
#8
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Post #8 by kevin205

Thank you Glen.

Using Zen Cart 1.5.1

1 Aug 2013, 11:20 PM
#9
dreamoutlaw avatar

dreamoutlaw

New Zenner

Join Date:
Feb 2010
Posts:
16
Plugin Contributions:
0

Post #9 by dreamoutlaw

I just tried this code modification using 'Categories Dressing' tpl_categories. I still can't hide my categories.