Try this:
<?php
/*
$Id: categories.php,v 1.0 2002/04/16 10:30:00 cl__ Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2002 Go?lette www.goelette.net
Christian Lescuyer <
[email protected]>
History: 1.0 Creation
Released under the GNU General Public License
*/
?>
<!-- categories_module //-->
<?php
define('SUB_CAT_MAX', 6); // Maximum number of subcategories to display
//////////
// Get categories list
//////////
// Test for presence of status field for compatibility with older versions
$status = tep_db_num_rows(tep_db_query('describe categories status'));
$query = "select c.categories_id, cd.categories_name, c.parent_id
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.categories_id = cd.categories_id";
if ($status > 0)
$query.= " and c.status = '1'";
$query.= " and cd.language_id='" . $languages_id ."'
order by sort_order, cd.categories_name";
$categories_query = tep_db_query($query);
// Stuff in an array
while ($category = tep_db_fetch_array($categories_query)) {
$categories[$category['categories_id']] = array('name' => $category['categories_name'], 'parent' => $category['parent_id']);
}
// Prepare the box
$info_box_contents = array();
$info_box_contents[] = array('align' => 'left', 'text' => BOX_HEADING_CATEGORIES);
new contentBoxHeading($info_box_contents);
$info_box_contents = array();
$row = 0;
$col = 0;
// Fill in the box
$cat_number = count($categories);
foreach ($categories as $id => $value) {
// Display only if top-level category
if ($value['parent'] == 0) {
$text = '<span class="smallText"><b>';
$text.= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $id) . '">';
$text.= $value['name'] . '</b></a><br>';
$sub_cat_count = 0;
// Get sub_categories, limit to SUB_CAT_MAX
for ($i = 0; $i < $cat_number && $sub_cat_count < SUB_CAT_MAX; $i++) {
if ($categories[$i]['parent'] == $id) {
$text .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $id . '_' . $i) . '">';
$text .= $categories[$i]['name'];
$text .= '</a>, ';
$sub_cat_count++;
}
}
// "more..."
$text .= '<b><a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $id) . '">more...</b></a>';
$text .= '</span>';
// Output box
$info_box_contents[$row][$col] = array('align' => 'left',
'params' => 'width="50%" valign="top"',
'text' => $text);
if (++$col > 1) {
$col = 0;
$row ++;
}
}
}
new contentBox($info_box_contents);
?>
<!-- categories_module_eof //-->
Actually, I've forgotten what it does :lol: Just try it!
Save as categories.php in includes/modules.
Then call with
<?php include(DIR_WS_MODULES . 'categories.php'); ?>