Contributions

Features (Category Index)
Search: 

Hide No product Category In Category Menu

Normally,Left Category Menu Box,will show all categories whatever it contain product or not.
I want hide category which do have any product in it. Look code below and it is easy.

file:includes/boxes/categories.php
replace tep_show_category function with:

function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array;

// DISABLE CATEGORY WITH NO PRODUCT
$bShowCategory = false;
$products_in_category = tep_count_products_in_category($counter);
if ($products_in_category > 0){

for ($i=0; $i<$tree[$counter]['level']; $i++) {
$categories_string .= "&nbsp;&nbsp;";
}

$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 .= '-&gt;';
}

$categories_string .= '</a>';

if (SHOW_COUNTS == 'true') {
$products_in_category = tep_count_products_in_category($counter);
if ($products_in_category > 0) {
$categories_string .= '&nbsp;(' . $products_in_category . ')';
}
}

$categories_string .= '<br>';
}

if ($tree[$counter]['next_id'] != false) {
tep_show_category($tree[$counter]['next_id']);
}
}

**********
Attach is dummy ,no any content.
**********
enjoy.

Expand All / Collapse All

Hide No product Category In Category Menu 31 Jul 2009

Normally,Left Category Menu Box,will show all categories whatever it contain product or not.
I want hide category which do have any product in it. Look code below and it is easy.

file:includes/boxes/categories.php
replace tep_show_category function with:

function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array;

// DISABLE CATEGORY WITH NO PRODUCT
$bShowCategory = false;
$products_in_category = tep_count_products_in_category($counter);
if ($products_in_category > 0){

for ($i=0; $i<$tree[$counter]['level']; $i++) {
$categories_string .= "&nbsp;&nbsp;";
}

$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 .= '-&gt;';
}

$categories_string .= '</a>';

if (SHOW_COUNTS == 'true') {
$products_in_category = tep_count_products_in_category($counter);
if ($products_in_category > 0) {
$categories_string .= '&nbsp;(' . $products_in_category . ')';
}
}

$categories_string .= '<br>';
}

if ($tree[$counter]['next_id'] != false) {
tep_show_category($tree[$counter]['next_id']);
}
}

**********
Attach is dummy ,no any content.
**********
enjoy.

Note: Contributions are used at own risk.