Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help! Show subcategories on parent category page


DeidreDee

Recommended Posts

Okay, so basically I have my categories listed in a horizontal menu at the top of my page (The parent categories only, not sub categories).

Now, what I want to do is that when you click on one of the parent categories, I want to display all the subcategories of that specific parent category, in the sidebar.

 

The default template of oscommerce shows the subcategories but it shows it with all the parent categories in one box. I want to show only the subcategories of each parent page.

 

Example: If someone clicks on the category "movies" in the horizontal menu... Once I'm on the "movies" page, it should show all the sub categories of movies (like Drama, Comedy etc.) in the sidebar. And when you click on a product in one of those categories it should continue to show it... only once you click on a new Parent category, it should switch again.

 

I hope this is making sense. I tried to edit the categorybox, but I don't get how I can split the subcategories from the categories.

 

Will this require a mod? If so, does anyone know of one?

Link to comment
Share on other sites

  • 6 months later...
  • 1 month later...
  • 2 weeks later...

backup your includes/boxes/categories.php and try this code instead:

 

<?php

/*

$Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

 

Modified by Monika Mathé

http://www.monikamathe.com

 

Module Copyright © 2006 Monika Mathé

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

function tep_show_category($counter) {

global $tree, $categories_string, $cPath_array;

 

if ($tree[$counter]['parent'] == 0) {

$cPath_new = 'cPath=' . $counter;

} else {

$cPath_new = 'cPath=' . $tree[$counter]['path'];

}

 

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

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

}

 

if (isset($cPath_array) && in_array($counter, $cPath_array)) {

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

$categories_string .= '<b>';

}

}

 

// display category name

$categories_string .= $tree[$counter]['name'];

 

if (isset($cPath_array) && in_array($counter, $cPath_array)) {

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

$categories_string .= '</b>';

}

}

 

if (!$tree[$counter]['parent'] == 0) {

$categories_string .= '</a><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);

 

if (isset($cPath) && tep_not_null($cPath) && tep_has_category_subcategories($cPath)) {

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 c.categories_id = '" . $cPath . "' and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");

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

 

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 //-->

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

  • 3 weeks later...

Archived

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

×
×
  • Create New...