OSCOMMERCE SUPPORT CALL 702-453-3332

 

Help - Search - Members - Calendar
Full Version: This is how you hide subcategories in "Categories"
osCommerce Community Support Forums > osCommerce Online Merchant v2.x > Tips and Tricks
EricB
This took me forever to figure out, but I finally did it biggrin.gif

I know some others out there wanted to get rid of the subcategories, but there didn't seem to be anyone able to tell us how to do it. Now hopefully, this will help you:

In the includes>boxes>categories.php file at around line 93 (if you haven't changed anything, anyway) you should see the following lines:
CODE
 //------------------------
 if (tep_not_null($cPath)) {
   $new_path = '';
   reset($cPath_array);
   while (list($key, $value) = each($cPath_array)) {
     unset($parent_id);
     unset($first_id);
     $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
     if (tep_db_num_rows($categories_query)) {
       $new_path .= $value;

and so on.

Change the //----------------------
to
/*----------This section prints the subcategories. Comment out to keep them hidden------------------

Now, go down to
CODE
 }
 tep_show_category($first_element);
 $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);
 new infoBox($info_box_contents);

and change to
CODE
 }
 */
 tep_show_category($first_element);
 $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);
 new infoBox($info_box_contents);

Now just save and upload!

Hope this helps!
TAPAKAH
THANKS A LOT!!! works great!
Draven
When I first saw this thread, I couldn't imagine why I would want to hide sub-categories.

However, I just implemented coolMenu and was trying to come up with the best way to make the categories menu functional for users who have JS disabled. I came up with the idea of 'hiding' the regular menu underneath coolMenu but obviously it was a mess when the sub-cats popped into view.

Anyway --- by disabling the display of sub-cats, coolMenu now stays perfectly positioned and everything displays perfectly (sans sub-cats) with JS off as well.

Thanks for the tip m8. smile.gif
h4ppy_girl
I tried doing this and have this error:


Warning: Unterminated comment starting line 92 in /home/virtual/site23/fst/var/www/html/oscommerce/includes/boxes/shopping_cart.php on line 92

Fatal error: Cannot redeclare tep_show_category() (previously declared in /home/virtual/site23/fst/var/www/html/oscommerce/includes/boxes/categories.php:13) in /home/virtual/site23/fst/var/www/html/oscommerce/includes/boxes/shopping_cart.php on line 13

Can you tell me the problem. Here is the code:
CODE
<?php
/*
 $Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 function tep_show_category($counter) {
   global $tree, $categories_string, $cPath_array;

   for ($i=0; $i<$tree[$counter]['level']; $i++) {
     $categories_string .= "&nbsp;&nbsp;";
   }

   $categories_string .= '<a href="';

   if ($tree[$counter]['parent'] == 0) {
     $cPath_new = 'cPath=' . $counter;
   } else {
     $cPath_new = 'cPath=' . $tree[$counter]['path'];
   }

   $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '<b>';
   }

// display category name
   $categories_string .= $tree[$counter]['name'];

   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '</b>';
   }

   if (tep_has_category_subcategories($counter)) {
     $categories_string .= '-&gt;';
   }

   $categories_string .= '</a>';

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

   $categories_string .= '<br>';

   if ($tree[$counter]['next_id'] != false) {
     tep_show_category($tree[$counter]['next_id']);
   }
 }
?>
<!-- categories //-->
         <tr>
           <td>
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

 new infoBoxHeading($info_box_contents, true, false);

 $categories_string = '';
 $tree = array();

 $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
 while ($categories = tep_db_fetch_array($categories_query))  {
   $tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                               'parent' => $categories['parent_id'],
                                               'level' => 0,
                                               'path' => $categories['categories_id'],
                                               'next_id' => false);

   if (isset($parent_id)) {
     $tree[$parent_id]['next_id'] = $categories['categories_id'];
   }

   $parent_id = $categories['categories_id'];

   if (!isset($first_element)) {
     $first_element = $categories['categories_id'];
   }
 }

 /*------------------------
 if (tep_not_null($cPath)) {
   $new_path = '';
   reset($cPath_array);
   while (list($key, $value) = each($cPath_array)) {
     unset($parent_id);
     unset($first_id);
     $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
     if (tep_db_num_rows($categories_query)) {
       $new_path .= $value;
       while ($row = tep_db_fetch_array($categories_query)) {
         $tree[$row['categories_id']] = array('name' => $row['categories_name'],
                                              'parent' => $row['parent_id'],
                                              'level' => $key+1,
                                              'path' => $new_path . '_' . $row['categories_id'],
                                              'next_id' => false);

         if (isset($parent_id)) {
           $tree[$parent_id]['next_id'] = $row['categories_id'];
         }

         $parent_id = $row['categories_id'];

         if (!isset($first_id)) {
           $first_id = $row['categories_id'];
         }

         $last_id = $row['categories_id'];
       }
       $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
       $tree[$value]['next_id'] = $first_id;
       $new_path .= '_';
     } else {
       break;
     }
   }  }
*/
tep_show_category($first_element);
$info_box_contents = array();
$info_box_contents[] = array('text' => $categories_string);
new infoBox($info_box_contents);
?>
           </td>
         </tr>
<!-- categories_eof //-->
crash3903
you have a blank line at the top of the page

delete the blank line and that should resolve it :-)

Alos make sure you have no blank lines at the bottom ;-)

regads

mark
Berberer
do you have a page where i can see what it will look like?? thanks !
Druide
QUOTE (h4ppy_girl @ Sep 1 2004, 04:30 PM)
I tried doing this and have this error:


Warning: Unterminated comment starting line 92 in /home/virtual/site23/fst/var/www/html/oscommerce/includes/boxes/shopping_cart.php on line 92

Fatal error: Cannot redeclare tep_show_category() (previously declared in /home/virtual/site23/fst/var/www/html/oscommerce/includes/boxes/categories.php:13) in /home/virtual/site23/fst/var/www/html/oscommerce/includes/boxes/shopping_cart.php on line 13

Can you tell me the problem. Here is the code:
CODE
<?php
/*
 $Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 function tep_show_category($counter) {
   global $tree, $categories_string, $cPath_array;

   for ($i=0; $i<$tree[$counter]['level']; $i++) {
     $categories_string .= "&nbsp;&nbsp;";
   }

   $categories_string .= '<a href="';

   if ($tree[$counter]['parent'] == 0) {
     $cPath_new = 'cPath=' . $counter;
   } else {
     $cPath_new = 'cPath=' . $tree[$counter]['path'];
   }

   $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '<b>';
   }

// display category name
   $categories_string .= $tree[$counter]['name'];

   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '</b>';
   }

   if (tep_has_category_subcategories($counter)) {
     $categories_string .= '-&gt;';
   }

   $categories_string .= '</a>';

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

   $categories_string .= '<br>';

   if ($tree[$counter]['next_id'] != false) {
     tep_show_category($tree[$counter]['next_id']);
   }
 }
?>
<!-- categories //-->
         <tr>
           <td>
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

 new infoBoxHeading($info_box_contents, true, false);

 $categories_string = '';
 $tree = array();

 $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
 while ($categories = tep_db_fetch_array($categories_query))  {
   $tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                               'parent' => $categories['parent_id'],
                                               'level' => 0,
                                               'path' => $categories['categories_id'],
                                               'next_id' => false);

   if (isset($parent_id)) {
     $tree[$parent_id]['next_id'] = $categories['categories_id'];
   }

   $parent_id = $categories['categories_id'];

   if (!isset($first_element)) {
     $first_element = $categories['categories_id'];
   }
 }

 /*------------------------
 if (tep_not_null($cPath)) {
   $new_path = '';
   reset($cPath_array);
   while (list($key, $value) = each($cPath_array)) {
     unset($parent_id);
     unset($first_id);
     $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
     if (tep_db_num_rows($categories_query)) {
       $new_path .= $value;
       while ($row = tep_db_fetch_array($categories_query)) {
         $tree[$row['categories_id']] = array('name' => $row['categories_name'],
                                              'parent' => $row['parent_id'],
                                              'level' => $key+1,
                                              'path' => $new_path . '_' . $row['categories_id'],
                                              'next_id' => false);

         if (isset($parent_id)) {
           $tree[$parent_id]['next_id'] = $row['categories_id'];
         }

         $parent_id = $row['categories_id'];

         if (!isset($first_id)) {
           $first_id = $row['categories_id'];
         }

         $last_id = $row['categories_id'];
       }
       $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
       $tree[$value]['next_id'] = $first_id;
       $new_path .= '_';
     } else {
       break;
     }
   }  }
*/
tep_show_category($first_element);
$info_box_contents = array();
$info_box_contents[] = array('text' => $categories_string);
new infoBox($info_box_contents);
?>
           </td>
         </tr>
<!-- categories_eof //-->

guys&gals can you read error messages ???

tep_show_category() (previously declared in /home/virtual/site23/fst/var/www/html/oscommerce/includes/boxes/categories.php:13


that means that function tep_show_category()
already exists & is allready defined in includes/boxes/categories.php line 13 !!!
h4ppy_girl
Thanks for help. I had actually changed something in the shoppin_cart that messed things up. Back on track!
osjunkie
I did this and my coolmenu still shows the sub categories. What am I missing?
rcr121
Can anyone tell me how to do this, so that ONLY the subcategories show? I don't want the top level to appear in my categories box, and I can't figure out how to supress it!!


Thanks in advance,



RCR
FrancineNJ
I orginally posted this in General Support...and received no answer. When I came across this thread actually talking about categories.php.....I thought I'd try it here.

Before my site went live...I moved everything up at of the "catalog" directory to the root.

I then started having a problem with my categories.php.
Besides products that are added thru the admin to the site (videos etc), at the bottom I had links to books, music, poster pages.
Those links were pointing to catalog/comedy_books.php. So, I downloaded the file...categories.php and found that these links had catalog/comedy_books.php in the link. I then removed all mention of catalog in their links and re-uploaded it.
I then created a separate box for the books and this is working fine.
Only thing is.....after editing the categories.php file and deleting all the links for the books, music, and posters. They still show up as though I never edited the file. And now I have two boxes showing books.
Also, when you first go over you don't see the books, music, posters in the first box. However if you click on the books link in the second box...the second page shows my problem....the first box with books, music, posters in it. UGH!!!!!! pinch.gif

Can someone tell me what do I need to do, to not have the books, music and poster in the categories box not show without doing away with that entire box.

Thank you,

You can see this problem at: SimplyPink - it is a live site.
oscommerceking
QUOTE (FrancineNJ @ Jul 22 2005, 10:47 AM)
I orginally posted this in General Support...and received no answer. When I came across this thread actually talking about categories.php.....I thought I'd try it here.

Before my site went live...I moved everything up at of the "catalog" directory to the root.

I then started having a problem with my categories.php.
Besides products that are added thru the admin to the site (videos etc), at the bottom I had links to books, music, poster pages.
Those links were pointing to catalog/comedy_books.php. So, I downloaded the file...categories.php and found that these links had catalog/comedy_books.php in the link. I then removed all mention of catalog in their links and re-uploaded it.
I then created a separate box for the books and this is working fine.
Only thing is.....after editing the categories.php file and deleting all the links for the books, music, and posters. They still show up as though I never edited the file. And now I have two boxes showing books.
Also, when you first go over you don't see the books, music, posters in the first box. However if you click on the books link in the second box...the second page  shows my problem....the first box with books, music, posters in it.  UGH!!!!!!  pinch.gif

Can someone tell me what do I need to do, to not have the books, music and poster in the categories box not show without doing away with that entire box.

Thank you,

You can see this problem at: SimplyPink - it is a live site.
*



Anyone know how to eliminate subcategories in the advanced search drop down list??????????




PPPPPPPPPPPLease help im desperate

Jon
mkered77
Go to advanced_search.php and find:
CODE
<tr>
   <td class="fieldKey"><?php echo ENTRY_CATEGORIES; ?></td>
   <td class="fieldValue"><?php echo tep_draw_pull_down_menu('categories_id', tep_get_categories(array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES)))); ?>
   </td>
</tr>

comment it out or delete it. This will get rid of categories on advanced search page.
oscommerceking
QUOTE (mkered77 @ Aug 4 2005, 06:00 PM)
Go to advanced_search.php and find:
CODE
<tr>
   <td class="fieldKey"><?php echo ENTRY_CATEGORIES; ?></td>
   <td class="fieldValue"><?php echo tep_draw_pull_down_menu('categories_id', tep_get_categories(array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES)))); ?>
   </td>
</tr>

comment it out or delete it.  This will get rid of categories on advanced search page.
*


Will this hide only subcategories, i want to make categories still visible , just hide the subs

Thanks for the quick response

Jon
oscommerceking
QUOTE (oscommerceking @ Aug 5 2005, 01:23 AM)
Will this hide only subcategories, i want to make categories still visible , just hide the subs

Thanks for the quick response

Jon
*


To anyone with the same question:


Click here for contribution + solution

Cheers

Jon
thomasking
I know this is a little unrelated to the exact topic, but somehow similar... tried searching for similar topic and couldnt find it...

What I would like to do is remove the standard -> extension after a category that has sub cats, but instead have a plus or minus box icon before it, like windows explorer. I am sure there is a contrib for this, just cant find it.
abayyari
QUOTE (thomasking @ Aug 16 2005, 03:09 PM)
I know this is a little unrelated to the exact topic, but somehow similar... tried searching for similar topic and couldnt find it...

What I would like to do is remove the standard -> extension after a category that has sub cats, but instead have a plus or minus box icon before it, like windows explorer. I am sure there is a contrib for this, just cant find it.
*


Look for this code block in categories.php

if (tep_has_category_subcategories($counter)) {
$categories_string .= '-&gt;';
}


Change the '-&gt' to a plus sign '+'. You can more the entire piece of code upwards in the file if you want the plus sign to be displayed before the category name.

Hope that helps. Cheers!
Ahmed
eww
somewhat of a similar problem i'm having:

i want the subcategories to have a different color/style from the regular category links, how can i achieve this?

this i what i want:
regular category1
- nested category1
- nested category2
regular category2
regular category3
eww
anyone know?
rhodgkiss2001
QUOTE (EricB @ Jul 13 2004, 01:16 AM) *
This took me forever to figure out, but I finally did it biggrin.gif

I know some others out there wanted to get rid of the subcategories, but there didn't seem to be anyone able to tell us how to do it. Now hopefully, this will help you:

In the includes>boxes>categories.php file at around line 93 (if you haven't changed anything, anyway) you should see the following lines:
CODE
 //------------------------
 if (tep_not_null($cPath)) {
   $new_path = '';
   reset($cPath_array);
   while (list($key, $value) = each($cPath_array)) {
     unset($parent_id);
     unset($first_id);
     $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
     if (tep_db_num_rows($categories_query)) {
       $new_path .= $value;

and so on.

Change the //----------------------
to
/*----------This section prints the subcategories. Comment out to keep them hidden------------------

Now, go down to
CODE
 }
 tep_show_category($first_element);
 $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);
 new infoBox($info_box_contents);

and change to
CODE
 }
 */
 tep_show_category($first_element);
 $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);
 new infoBox($info_box_contents);

Now just save and upload!

Hope this helps!
kwalker
QUOTE (abayyari @ Sep 11 2005, 09:16 PM) *
Look for this code block in categories.php

if (tep_has_category_subcategories($counter)) {
$categories_string .= '-&gt;';
}
Change the '-&gt' to a plus sign '+'. You can more the entire piece of code upwards in the file if you want the plus sign to be displayed before the category name.

Hope that helps. Cheers!
Ahmed


Cool, I like that!

Kevin
ely2c
This is sort of relevant.

I have a website with top level categories, subcategories and the products under the subcategories.

On the homepage I only want to show the Top level Categories, however when I click on a Category I only want to see the subcategory of that Category. Does this make sense?

Appreciate anyones help. This will really make navigation a lot easier for the user.
Thanks in advance.
amx_dk
QUOTE (ely2c @ Mar 8 2006, 12:43 AM) *
This is sort of relevant.

I have a website with top level categories, subcategories and the products under the subcategories.

On the homepage I only want to show the Top level Categories, however when I click on a Category I only want to see the subcategory of that Category. Does this make sense?

Appreciate anyones help. This will really make navigation a lot easier for the user.
Thanks in advance.


Did you figure this out? I want the same thing. (I think)

I want my categories to show like this.

top categories
(show items if any)
sub categories
(show all items in sub categories)

is this possible in any way? I have been trying to figure this out for ages. sad.gif
PJ2006
QUOTE (oscommerceking @ Aug 6 2005, 06:56 AM) *
To anyone with the same question:
Click here for contribution + solution

Cheers

Jon

I want a search box that only lists the sub-categories for the selected category - is that an option?
WizUnder
QUOTE (EricB @ Jul 13 2004, 01:16 AM) *
This took me forever to figure out, but I finally did it biggrin.gif

I know some others out there wanted to get rid of the subcategories, but there didn't seem to be anyone able to tell us how to do it. Now hopefully, this will help you:

In the includes>boxes>categories.php file at around line 93 (if you haven't changed anything, anyway) you should see the following lines:
CODE
  //------------------------
  if (tep_not_null($cPath)) {
    $new_path = '';
    reset($cPath_array);
    while (list($key, $value) = each($cPath_array)) {
      unset($parent_id);
      unset($first_id);
      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
      if (tep_db_num_rows($categories_query)) {
        $new_path .= $value;

and so on.

Change the //----------------------
to
/*----------This section prints the subcategories. Comment out to keep them hidden------------------

Now, go down to
CODE
  }
  tep_show_category($first_element);
  $info_box_contents = array();
  $info_box_contents[] = array('text' => $categories_string);
  new infoBox($info_box_contents);

and change to
CODE
  }
  */
  tep_show_category($first_element);
  $info_box_contents = array();
  $info_box_contents[] = array('text' => $categories_string);
  new infoBox($info_box_contents);

Now just save and upload!

Hope this helps!



biggrin.gif Thank you very much. I have been working on this all morning today. Eventually, everything is just coming out the way I want it to be. I added a css menu to make the categories more appealing. Here is my test site http://netcheaperdeals.com/ the colors the not final yet, but it is pretty much close to its final appearance, once I uploaded the big header graphics and some table refinements.

Thanks again for your contribution...This is the only way you can avoid the subcategories going out of control within the CSS menu..
cjpopp
QUOTE (eww @ Sep 25 2005, 04:12 PM) *
somewhat of a similar problem i'm having:

i want the subcategories to have a different color/style from the regular category links, how can i achieve this?

this i what i want:
regular category1
- nested category1
- nested category2
regular category2
regular category3



I saw this post when I was looking for the same answer but found that no one answered it.

So, does anyone know how to make the sub-categories look different or stand out?
spooks
There is a contrib I`ve done Hide Categories & Products http://addons.oscommerce.com/info/5907 which allows you to selectively hide any category or sub-category
cjpopp
QUOTE (spooks @ Jun 6 2008, 06:53 AM) *
There is a contrib I`ve done Hide Categories & Products http://addons.oscommerce.com/info/5907 which allows you to selectively hide any category or sub-category


Yea, but I want to show the sub-categories and make them indented so they don't just "bleed" into the main categories.
spooks
QUOTE (cjpopp @ Jun 6 2008, 02:26 PM) *
Yea, but I want to show the sub-categories and make them indented so they don't just "bleed" into the main categories.


Sorry, I must have been confused by the topic title 'how you hide subcategories'
Jenphi
QUOTE (EricB @ Jul 12 2004, 07:16 PM) *
This took me forever to figure out, but I finally did it biggrin.gif
**Insert Strategically Placed Commented Out Lines**
Hope this helps!


I love you! This helps so much! Thanks!!!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.