Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

show - hide categories


Guest

Recommended Posts

I'd like to hide empty categories so that they do not display in the menu when there are no products. Is there a way to do this? I've searched help and also searched contributions.

 

Thanks in advance.

 

Anne

Link to comment
Share on other sites

Around lines 47-52 in includes/boxes/categories.php find the following code

    if (SHOW_COUNTS == 'true') {
     $products_in_category = tep_count_products_in_category($counter);
     if ($products_in_category > 0) {
       $categories_string .= ' (' . $products_in_category . ')';
     }
   }

Move the second and third lines (48-9) to line 16, so lines 14-18 look like this:

    global $tree, $categories_string, $cPath_array;

   $products_in_category = tep_count_products_in_category($counter);
   if ($products_in_category > 0) {
     for ($i=0; $i<$tree[$counter]['level']; $i++) {

and move the fifth line (51) to line 54 so lines 53-56 look like this

      $categories_string .= '<br>';
   }

   if ($tree[$counter]['next_id'] != false) {

Lines 49-51 will look like this:

      if (SHOW_COUNTS == 'true') {
       $categories_string .= ' (' . $products_in_category . ')';
     }

Note: you should probably adjust the indenting from lines 18-55. I have already done it in these snippets. Those lines not shown that are in that range will each need to be indented two more spaces to be consistent. Won't affect functionality, just make it easier to read.

 

Btw, if you have a lot of products, this will slow down your store noticeably if you had SHOW_COUNTS off previously (on or off won't matter now--same speed).

 

Hth,

Matt

Link to comment
Share on other sites

  • 2 years later...
  • 2 weeks later...
but what about the subcategories that display with images inside the categories? Is there a way of hiding those too?

hi,

i also have the problem that the subcategories where shown with the image.

what can i do against that?

 

greetz

tali

Link to comment
Share on other sites

  • 3 months later...
Around lines 47-52 in includes/boxes/categories.php find the following code
	if (SHOW_COUNTS == 'true') {
  $products_in_category = tep_count_products_in_category($counter);
  if ($products_in_category > 0) {
	$categories_string .= ' (' . $products_in_category . ')';
  }
}

Move the second and third lines (48-9) to line 16, so lines 14-18 look like this:

	global $tree, $categories_string, $cPath_array;

$products_in_category = tep_count_products_in_category($counter);
if ($products_in_category > 0) {
  for ($i=0; $i<$tree[$counter]['level']; $i++) {

and move the fifth line (51) to line 54 so lines 53-56 look like this

	  $categories_string .= '<br>';
}

if ($tree[$counter]['next_id'] != false) {

Lines 49-51 will look like this:

	  if (SHOW_COUNTS == 'true') {
	$categories_string .= ' (' . $products_in_category . ')';
  }

Note: you should probably adjust the indenting from lines 18-55. I have already done it in these snippets. Those lines not shown that are in that range will each need to be indented two more spaces to be consistent. Won't affect functionality, just make it easier to read.

 

Btw, if you have a lot of products, this will slow down your store noticeably if you had SHOW_COUNTS off previously (on or off won't matter now--same speed).

 

Hth,

Matt

 

Brilliant, I've spent hours trying to do this.

Thanks for the info.

 

Works perfectly for me too :thumbsup:

Link to comment
Share on other sites

  • 6 months later...
This worked for me, but what about the subcategories that display with images inside the categories? Is there a way of hiding those too?

 

I also wish to remove the images inside the categories for the empty subcategories. Is there a solution?

Link to comment
Share on other sites

I also wish to remove the images inside the categories for the empty subcategories. Is there a solution?

in catalog/index.php around line 100 find

while ($categories = tep_db_fetch_array($categories_query)) {

just after it add

$products_in_category = tep_count_products_in_category($categories['categories_id']);

if($products_in_category > 0){

Then around line 107 find

echo ' <tr>' . "\n";

Right after it add

}

Link to comment
Share on other sites

Jason, on that contirb, will it hide the empty categories automaticly or do we have to do it from the admin after every order has been placed?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...