osCommerce Main Categories Content Customization Example
Example 3 - Add horizontal line under Parent Categories
Some osCommerce shop owner like to add a horizontal line (<hr>) under the Parent Categories. This is shown in the picture below:



This is quite interesting. Let's add a horizontal line to the Parent Categories.
This is clear that we can modify the code below highlight in red color to accomplish the result.
function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array;
for ($i=0; $i<$tree[$counter]['level']; $i++) {
$categories_string .= tep_image(DIR_WS_IMAGES . 'main_categories_bullet.gif', '');
}
$categories_string .= '<a href="';
if ($tree[$counter]['parent'] == 0) {
$cPath_new = 'cPath=' . $counter;
} else {
$cPath_new = 'cPath=' . $tree[$counter]['path'];
}
$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';
if (isset($cPath_array) && in_array($counter, $cPath_array)) {
$categories_string .= '<b>';
}
// display category name
$categories_string .= $tree[$counter]['name'];
if (isset($cPath_array) && in_array($counter, $cPath_array)) {
$categories_string .= '</b>';
}
/*
if (tep_has_category_subcategories($counter)) {
$categories_string .= '->';
}
*/
$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 . ')';
}
}
*/
$categories_string .= '<br>';
if ($tree[$counter]['next_id'] != false) {
tep_show_category($tree[$counter]['next_id']);
}
}
Add horizontal line under Parent Categories
This is rather easy.
- If this is a Parent Categories, add a <hr> horizontal line
- If this is not a Parent Categories (i.e. Sub-Categories), add a <br> line return as before
Therefore the codes become:
function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array;
for ($i=0; $i<$tree[$counter]['level']; $i++) {
$categories_string .= tep_image(DIR_WS_IMAGES . 'main_categories_bullet.gif', '');
}
$categories_string .= '<a href="';
if ($tree[$counter]['parent'] == 0) {
$cPath_new = 'cPath=' . $counter;
} else {
$cPath_new = 'cPath=' . $tree[$counter]['path'];
}
$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';
if (isset($cPath_array) && in_array($counter, $cPath_array)) {
$categories_string .= '<b>';
}
// display category name
$categories_string .= $tree[$counter]['name'];
if (isset($cPath_array) && in_array($counter, $cPath_array)) {
$categories_string .= '</b>';
}
/*
if (tep_has_category_subcategories($counter)) {
$categories_string .= '->';
}
*/
$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 .= '<hr>';
} else {
$categories_string .= '<br>';
}
if ($tree[$counter]['next_id'] != false) {
tep_show_category($tree[$counter]['next_id']);
}
}
Now, we know how to add horizontal line under Parent Categories of osCommerce Main Categories.