al3ks Posted July 28, 2012 Share Posted July 28, 2012 I am trying to make like a customer side sitemap of all categories on one page. I have tried using the bm_categories.php file as a guide to output all categories (including sub-categories) on a page, but failed. Does anyone know how to this can be done? Regards Aleksander Find this post helpful? Click the 'Like this' button. :) Link to comment Share on other sites More sharing options...
germ Posted July 29, 2012 Share Posted July 29, 2012 Code I cabbaged from some download years ago. I'd give them credit if I could remember where I got it. :blush: It's just the raw code needed to display all category/ subcategory links. You'll have to work it into your custom page. Good luck. <?php require('includes/application_top.php'); $language_code = (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) ? $HTTP_GET_VARS['language'] : DEFAULT_LANGUAGE; $included_categories_query = tep_db_query("SELECT c.categories_id, c.parent_id, cd.categories_name FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id AND cd.language_id = FLOOR($languages_id)"); $inc_cat = array(); while ($included_categories = tep_db_fetch_array($included_categories_query)) { $inc_cat[] = array ( 'id' => $included_categories['categories_id'], 'parent' => $included_categories['parent_id'], 'name' => $included_categories['categories_name']); } $cat_info = array(); for ($i=0; $i<sizeof($inc_cat); $i++) $cat_info[$inc_cat[$i]['id']] = array ( 'parent'=> $inc_cat[$i]['parent'], 'name' => $inc_cat[$i]['name'], 'path' => $inc_cat[$i]['id'], 'link' => '' ); for ($i=0; $i<sizeof($inc_cat); $i++) { $cat_id = $inc_cat[$i]['id']; while ($cat_info[$cat_id]['parent'] != 0){ $cat_info[$inc_cat[$i]['id']]['path'] = $cat_info[$cat_id]['parent'] . '_' . $cat_info[$inc_cat[$i]['id']]['path']; $cat_id = $cat_info[$cat_id]['parent']; } $link_array = split('_', $cat_info[$inc_cat[$i]['id']] ['path']); for ($j=0; $j<sizeof($link_array); $j++) { if ( $j != (sizeof($link_array)-1) ) $cat_info[$inc_cat[$i]['id']]['link'] .= ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cat_info[$link_array[$j]]['path']) . '"><nobr>' . $cat_info[$link_array[$j]]['name'] . '</nobr></a> - '; else $cat_info[$inc_cat[$i]['id']]['link'] .= ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cat_info[$link_array[$j]]['path']) . '"><nobr>' . $cat_info[$link_array[$j]]['name'] . '</nobr></a>'; } echo $cat_info[$inc_cat[$i]['id']]['link'] , '<br>'; } ?> If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
al3ks Posted July 29, 2012 Author Share Posted July 29, 2012 @@germ Thanks for this, really appreciate it. I have just one problem, i want to order the list by alphabetical ascending order, so I have used ORDER BY cd.categories_name ASC to the end of the included_categories_query. The problem is it order alphabetically sub-categories and categories as one, so if there is a main category with first letter B and sub-category with letter A it is shown above the main category. Would you know how to sort it so main categories are order ascending and their respective sub categories are under the main categories in ascending order? Thanks for the code anyway though... Find this post helpful? Click the 'Like this' button. :) Link to comment Share on other sites More sharing options...
♥14steve14 Posted July 29, 2012 Share Posted July 29, 2012 Have you thought to look to see if there is an addon already that you could then alter the code to fit with what you want. There is a very good sitemap addon at http://addons.oscommerce.com/info/8280 REMEMBER BACKUP, BACKUP AND BACKUP Link to comment Share on other sites More sharing options...
al3ks Posted July 29, 2012 Author Share Posted July 29, 2012 Have you thought to look to see if there is an addon already that you could then alter the code to fit with what you want. There is a very good sitemap addon at http://addons.oscommerce.com/info/8280 Thanks this is perfect! Find this post helpful? Click the 'Like this' button. :) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.