Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Categories Menu -- Hide other parents when within a category


CodeConfused

Recommended Posts

Posted

Hi All,

 

We are setting up a store with hundreds of categories...

If a customer clicks on a category that has subcategories, it would be great if there was a way to hide the other parent categories, with maybe a link like "return to top", to get back up?

 

For example, let's say this is how our entire tree looked like if mapped out:

 

-Parent Category A

-Subcategory 1

-Subcategory 2

-Subcategory 3

-Parent Category B

-Parent Category C

 

 

I would now like to find a way to -when a customer clicks on "Category A"- to have it go into Parent Category A, and hide B and C, and show the following:

 

-Return To Top

-Parent Category A

-Subcategory 1

-Subcategory 2

-Subcategory 3

 

The "Return to Top" link would take it back up to show again only:

 

-Parent Category A

-Parent Category B

-Parent Category C

 

I have honestly searched the forum backwards and forwards, but couldn't find a solution or contribution for this problem.

 

Your thoughts are much, much appreciated! :D

 

Thanks a million,

CodeConfused

Posted

I havent tested this because i dont use multi categories - but it will be something like ....

 

in includes/boxes/categories.php

 

look for

 

if (!isset($first_element)) {

     $first_element = $categories['categories_id'];

   }

 

and replace with ...

 

 

if (isset($cPath_array)) {

   for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {

     $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $cPath_array[$i] . "' and language_id='" . $languages_id . "'");

     if (tep_db_num_rows($categories_query) > 0) {

       $categories = tep_db_fetch_array($categories_query);

       } else {

       break;

     }

   }

 }

$my_category_name = $categories['categories_name'];

$first_element = $categories['categories_id'];

}

 

to put the link to return to top you would just need to hard code something like

 

$categories_string = '<a href="' . FILENAME_DEFAULT . '">Return to top</a><br>';

$categories_string = '<b>' . $my_category_name . '</b><br>';

 

just after

 

$info_box_contents = array();

 $info_box_contents[] = array('align' => 'left',

                              'text'  => BOX_HEADING_CATEGORIES

                             );

 new columnBoxHeading($info_box_contents, true, false);

 

 

best of luck

Posted

Thank you so much for this incredibly helpful post!

I'll play with this & tweak it a little!

 

Again, thanks a million!

 

Greetings,

Dan

  • 4 months later...
  • 1 year later...
  • 2 years later...
  • 4 months later...
Posted

Me too..

I sure wish I knew more coding..

yes a menu like amazon.

 

so I know there are genious out there that can do this.. please HELP

 

THANK YOU

Noppie

  • 4 weeks later...
Posted

<?php
require('includes/application_top.php');
if ( !isset($_GET['cPath']) ) {

$masters = tep_db_query("
SELECT c.categories_id, cd.categories_name
FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
WHERE c.parent_id = '0'
AND c.categories_id = cd.categories_id
AND language_id = '" . (int)$languages_id . "'
AND c.categories_status = '1'
order by sort_order, cd.categories_name
");

while ($m_cat = tep_db_fetch_array($masters))
echo '<a href="' . tep_href_link(basename($_SERVER['PHP_SELF']), 'cPath=' . $m_cat['categories_id']) . '" title="' . $m_cat['categories_name'] . '" >' . $m_cat['categories_name'] . '</a><br />';
tep_db_free_result($masters);
} else if ( isset($_GET['cPath']) && !strstr($_GET['cPath'], '_') ) {
$parent_cat = $_GET['cPath'];

$parent = tep_db_query("
SELECT c.categories_id, cd.categories_name
FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
WHERE c.categories_id = '$parent_cat'
AND language_id = '" . (int)$languages_id . "'
AND c.categories_status = '1'
order by sort_order, cd.categories_name
");

$parent_array = tep_db_fetch_array($parent);
tep_db_free_result($parent);
$children = tep_db_query("
SELECT c.categories_id, cd.categories_name
FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
WHERE parent_id = '$parent_cat'
AND c.categories_id = cd.categories_id
AND language_id = '" . (int)$languages_id . "'
AND c.categories_status = '1'
order by sort_order, cd.categories_name
");

echo '<a href="' . tep_href_link(basename($_SERVER['PHP_SELF']), 'cPath=' . $parent_cat) . '" title="' . $parent_array['categories_name'] . '"><b>' . $parent_array['categories_name'] . '</b></a><br />';
while ($child_array = tep_db_fetch_array($children))
echo '<a href="' . tep_href_link(basename($_SERVER['PHP_SELF']), 'cPath=' . $parent_cat . '_' . $child_array['categories_id']) . '" title="' . $child_array['categories_name'] . '" >' . $child_array['categories_name'] . '</a><br />';
} else die('Link path = ' . $_GET['cp'] . ' - we haven\'t done deeper level categories yet');
?>

 

One friend wrote this for me, I'm not able to implement this works, anyone can help to make this "new" way to show the categories work?

 

Tnx, Jo

Archived

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

×
×
  • Create New...