Show subcategory count after category name (v. 2.9x)
To show the number of subcategories under a category:
e.g.)
Main Category (3)
- Subcategory 1
- Subcategory 2
- Subcategory 3 (2)
- Subcategory A
- Subcategory B
- Subcategory 1
- Subcategory 2
- Subcategory 3 (2)
- Subcategory A
- Subcategory B
use the following modification:
-
Open the stconfig.php file in the main public folder.
-
Add the code:
// SUBCATEGORY COUNT $subcatcount = array(); $subcatresult=$dataconn->query("SELECT c.ID, c.Category, count(s.ID) AS subcount FROM " . SB_DB_PREFIX . "_categories c LEFT JOIN " . SB_DB_PREFIX . "_categories s ON c.ID=s.Parent GROUP BY c.ID;"); while($subcatrow = $subcatresult->fetch_assoc()) { $subcatcount[$subcatrow['ID']] = $subcatrow['subcount']; }just above the code:
// SHOW CATEGORIES if (!function_exists("setcategories"))around line 641.
-
A few lines down, change:
global $dataconn, $use_alt_kw, $ws_logged_in, $urldir, $wsnum, $curdr, $use_29;
to:
global $dataconn, $use_alt_kw, $ws_logged_in, $urldir, $wsnum, $curdr, $use_29, $subcatcount;
-
Add the code:
$set_dispval = str_replace("[%%SUBCATCOUNT%%]", (($subcatcount[$catrow[ID]] > 0) ? '(' . $subcatcount[$catrow[ID]] . ')' : ''), $set_dispval);just under the line:
$set_dispval = str_replace("[%%CATTITLE%%]", $set_cattitle, $set_dispval); -
To add the count after categories in the vertical navigation links (usually along the left side of the web site:
-
Open the navbar_vertical.php file in the /enc/ folder.
-
Change the code:
$vertbulk = "[%%INDENT%%][%%DISPLAY%%]";
to:
$vertbulk = "[%%INDENT%%][%%DISPLAY%%] [%%SUBCATCOUNT%%]";
-
-
To add the count after categories in the main area of the site when viewing the main catalog page or when viewing subcategories under a category:
-
Open the products_maincat.php file in the /enc/ folder.
-
Add the code:
$stripcat .= ($subcatcount[$maincatrow[ID]] > 0) ? ' (' . $subcatcount[$maincatrow[ID]] . ')' : '';just above the line:
// IMAGE SETTINGS
-