DeidreDee Posted December 31, 2009 Share Posted December 31, 2009 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 More sharing options...
Denz Posted July 20, 2010 Share Posted July 20, 2010 Hi DeidreDee, Did you find a solution to this? Cause this is exactly what I want too. Thanks Denz Link to comment Share on other sites More sharing options...
Mike8 Posted September 4, 2010 Share Posted September 4, 2010 Hey DeidreDee, have you got an idea? Really looking forward. Mike Link to comment Share on other sites More sharing options...
Tabula_Rasa Posted September 13, 2010 Share Posted September 13, 2010 Hey DeidreDee, have you got an idea? Really looking forward. Mike Did anybody solve this? If so, how? Link to comment Share on other sites More sharing options...
♥Monika in Germany Posted September 13, 2010 Share Posted September 13, 2010 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 More sharing options...
ashdeini Posted October 4, 2010 Share Posted October 4, 2010 Thank you Monika that is very helpful .. do you know of a way display the "parent category" in place the of BOX_HEADING_CATEGORIES ? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.