osjunkie Posted August 18, 2005 Share Posted August 18, 2005 Hey everybody! (Dr.Nick) I have main category tabs at the top of my header which work great but I have too many sub-cats for it to work effectively. I want to make categories.php only display the sub categories of a main category that I am viewing. Easy Hard? How would you hack it up to do it? Thanks, Brad Link to comment Share on other sites More sharing options...
developer_x Posted August 18, 2005 Share Posted August 18, 2005 Someone had posted a contrib for removing the sub categories only. You will have to try using it in the reverse manner. Hope that helps. Irfan, Link to comment Share on other sites More sharing options...
♥Monika in Germany Posted August 18, 2005 Share Posted August 18, 2005 Hey everybody! (Dr.Nick) I have main category tabs at the top of my header which work great but I have too many sub-cats for it to work effectively. I want to make categories.php only display the sub categories of a main category that I am viewing. Easy Hard? How would you hack it up to do it? Thanks, Brad <{POST_SNAPBACK}> pass the cat_id of the cat you click on in the header, and make the select statement only for this one. Comment out all code calling the name of this cat, and remove the spaces that indent the subcats. All done! :-) 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...
Guest Posted August 19, 2005 Share Posted August 19, 2005 pass the cat_id of the cat you click on in the header, and make the select statement only for this one. Comment out all code calling the name of this cat, and remove the spaces that indent the subcats. All done! <{POST_SNAPBACK}> I am trying to do the same thing here. Which query am I changing? Link to comment Share on other sites More sharing options...
♥Monika in Germany Posted August 19, 2005 Share Posted August 19, 2005 I modded it for you guys: see here in a test shop ... feeding has subcats for example http://www.noahsark4kids.com/test/index.php <?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 .= " "; $categories_string .= ""; } for ($i=0; $i<$tree[$counter]['level']; $i++) { $categories_string .= '<a href="'; } 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 .= 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 (tep_has_category_subcategories($counter)) { //$categories_string .= '->'; } for ($i=0; $i<$tree[$counter]['level']; $i++) { $categories_string .= '</a>'; } if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($counter); if ($products_in_category > 0) { $categories_string .= ' (' . $products_in_category . ')'; } } for ($i=0; $i<$tree[$counter]['level']; $i++) { $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 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)) { /* $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 //--> :-) 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...
Guest Posted August 19, 2005 Share Posted August 19, 2005 Monika, Thank you very much. I have one more question, on your store when you click the sub category, it works correctly. On mine, the categories look fine, but when I click a subcategory, it shows the top level categories again :-/. Is there another change I need to make besides the categories.php page? Link to comment Share on other sites More sharing options...
Guest Posted August 19, 2005 Share Posted August 19, 2005 oh wait.. it is fixed now... sometimes i dont understand. hah. Link to comment Share on other sites More sharing options...
osjunkie Posted August 19, 2005 Author Share Posted August 19, 2005 Strange...I am getting URL's in my category box on the 3rd level for each 3rd level category. I copied the code as posted. hmmmmmmmmmm http://www.xxxxxxx.com/hardware/notebook-a...ml">AMD Athlon64 Link to comment Share on other sites More sharing options...
♥Monika in Germany Posted August 19, 2005 Share Posted August 19, 2005 Strange...I am getting URL's in my category box on the 3rd level for each 3rd level category. I copied the code as posted. hmmmmmmmmmmhttp://www.xxxxxxx.com/hardware/notebook-a...ml">AMD Athlon64 <{POST_SNAPBACK}> well that link only takes me to a porn site ... guess that's not your shop right? I have not tested the code on 3rd levels and would need to see what you mean. :-) 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...
osjunkie Posted August 19, 2005 Author Share Posted August 19, 2005 well that link only takes me to a porn site ... guess that's not your shop right? I have not tested the code on 3rd levels and would need to see what you mean. <{POST_SNAPBACK}> Sorry, I should have used oooooo instead of xxxxxx. I will post a screen shot in a bit or you could make a 3rd level category on your page and see if it happens. :) Brad Link to comment Share on other sites More sharing options...
♥Monika in Germany Posted August 20, 2005 Share Posted August 20, 2005 Sorry, I should have used oooooo instead of xxxxxx. I will post a screen shot in a bit or you could make a 3rd level category on your page and see if it happens. :) Brad <{POST_SNAPBACK}> use this instead, you can have a look onthe same page, I added a cat to feeding/bottles <?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=1; $i<$tree[$counter]['level']; $i++) { $categories_string .= " "; //$categories_string .= ""; } for ($i=0; $i<$tree[$counter]['level']; $i++) { //$categories_string .= '<a href="'; } 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 (tep_has_category_subcategories($counter)) { //$categories_string .= '->'; } for ($i=1; $i<$tree[$counter]['level']; $i++) { $categories_string .= '</a>'; } if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($counter); if ($products_in_category > 0) { $categories_string .= ' (' . $products_in_category . ')'; } } if (!$tree[$counter]['parent'] == 0) { $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 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)) { /* $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 //--> :-) 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...
chuckyboy Posted August 21, 2005 Share Posted August 21, 2005 Im not a programmer, but i triad after 1,5 hours to editor categories.php, then I opened a browser, came here to oscommerce forum, searched for "categories.php", and 1 minutes solved my problem. Great. Im stupid.And thanks for the code. Link to comment Share on other sites More sharing options...
chuckyboy Posted August 21, 2005 Share Posted August 21, 2005 Maybe an error: if (!$tree[$counter]['parent'] == 0) { $categories_string .= '<br>'; change : if (!$tree[$counter]['parent'] == 0) { $categories_string .= '</a><br>'; The different is "</a>", becouse the categorie name is an "open link" without it. Link to comment Share on other sites More sharing options...
osjunkie Posted August 21, 2005 Author Share Posted August 21, 2005 Hmmmm.....still not ther yet. When I click on the final child category to view products I want the other non active sub categories to disappear and only show the active child categories. Example. First Click Computers (root) Video Cards Memory Speakers Second Click Computers Notebooks Handhelds Tablet PC Third Click Tablet PC 10" 12" 14" Is this more understandable? Link to comment Share on other sites More sharing options...
♥Monika in Germany Posted August 22, 2005 Share Posted August 22, 2005 Hmmmm.....still not ther yet. When I click on the final child category to view products I want the other non active sub categories to disappear and only show the active child categories. Example. First Click Computers (root) Video Cards Memory Speakers Second Click Computers Notebooks Handhelds Tablet PC Third Click Tablet PC 10" 12" 14" Is this more understandable? <{POST_SNAPBACK}> nope you did not make this clear at all. You were talking about the display of 3rd level cats. I'm sure though that with the code snippet I gave you you will be able to find the part to change for your needs. Have fun! :-) 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...
Kohn Posted March 30, 2007 Share Posted March 30, 2007 I desperately need to get this hack to work but really need some help. I tried using this but it will not work with our code. Can anybody please help me to see how to get the category to display only the subcategories? <?php function tep_show_category($counter) { global $tree, $categories_string, $cPath_array; if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($counter); if ($products_in_category > 0) { $category_counts = ' (' . $products_in_category . ')'; } } if ($tree[$counter]['parent'] == 0) { $cPath_new = 'cPath=' . $counter; if (isset($cPath_array) && in_array($counter, $cPath_array)) { $categories_string .= ' <a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '"><h2>' . $tree[$counter]['name'] . $category_counts . '</h2></a>'; } } else { $cPath_new = 'cPath=' . $tree[$counter]['path']; if (isset($cPath_array) && in_array($counter, $cPath_array)) { $colored_name = '<span style="color: #878787; font-weight: bold;">' . $tree[$counter]['name'] . '</span>'; } else { $colored_name = $tree[$counter]['name']; } $categories_string .= ' <p><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . $colored_name . '</a>' . $category_counts . '</p>'; } if ($tree[$counter]['next_id'] != false) { tep_show_category($tree[$counter]['next_id']); } else { echo $categories_string; } } $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)) { ?> <div id="categoryNav"> <h1><?php echo tep_image('bg_box_blue_1.gif', '', '161', '3'); ?></h1> <?php $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); ?> <h1><?php echo tep_image('bg_box_blue_2.gif', '', '161', '3'); ?></h1> </div> <?php } ?> PLEASE!! nope you did not make this clear at all. You were talking about the display of 3rd level cats. I'm sure though that with the code snippet I gave you you will be able to find the part to change for your needs. Have fun! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.