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

use the following modification:

  1. Open the stconfig.php file in the main public folder.

  2. 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.

  3. 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;
  4. 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);
  5. To add the count after categories in the vertical navigation links (usually along the left side of the web site:

    1. Open the navbar_vertical.php file in the /enc/ folder.

    2. Change the code:

      $vertbulk = "[%%INDENT%%][%%DISPLAY%%]";

      to:

      $vertbulk = "[%%INDENT%%][%%DISPLAY%%] [%%SUBCATCOUNT%%]";
  6. 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:

    1. Open the products_maincat.php file in the /enc/ folder.

    2. Add the code:

      $stripcat .= ($subcatcount[$maincatrow[ID]] > 0) ? ' (' . $subcatcount[$maincatrow[ID]] . ')' : '';

      just above the line:

      // IMAGE SETTINGS