Product count in Magento layered category navigation

Product count in Magento layered category navigation

August 10, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Product count in Magento layered category navigation

Displaying Product Counts in Magento Layered Category Navigation

As a developer new to Magento, you might find yourself scratching your head when trying to display product counts efficiently in the category menu. Fear not! This guide will walk you through a clean, non-hacky solution that leverages core Magento functionality.

Understanding the Problem

The default Magento layered navigation doesn’t come with built-in support for displaying product counts next to each category name. The Mage_Catalog_Block_Navigation class is responsible for rendering the menu items, but it lacks a straightforward method for retrieving this information.

A Clean Solution: Using Mage_Core_Model_Category

The key lies in using Magento’s core model classes that are designed to handle these tasks. Specifically, we’ll use Mage_Core_Model_Category which provides a method called getProductsCount() that returns the count of products assigned to a specific category.

Here’s an example of how you can integrate this into your layered navigation:

  1. Override Mage_Catalog_Block_Navigation

Create a new block class extending Mage_Catalog_Block_Navigation and override the _renderCategoryMenuItemHtml() method in your theme or custom extension:

class MyTheme_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation
{
    protected function _renderCategoryMenuItemHtml($category, $level)
    {
        // Your existing code here

        $productCount = $category->getProductsCount();

        if ($productCount > 0) {
            $menuItemHtml .= '<span class="count">(' . $productCount . ')</span>';
        }

        return $menuItemHtml;
    }
}
  1. Re-define the block in your layout XML

Make sure to re-define the navigation block in your template files:

<block type="catalog/navigation" name="catalog.navigation" before="-" template="catalog/navigation.phtml"/>

Additional Notes and Best Practices

When working with Magento, it’s essential to follow best practices for customization. This includes:

  • Using layout XML updates instead of direct file overwrites where possible.
  • Leveraging the core model classes rather than bypassing them entirely.
  • Keeping your theme separate from your core files.

Remember, every change you make directly in core files increases the risk of conflicts during upgrades. It’s always better to work within Magento’s framework and use the tools it provides for customization.

Conclusion

Displaying product counts in the layered category navigation is a common requirement that can be achieved efficiently using Magento’s built-in models. By following this guide, you should now have a clean, non-hacky solution that respects Magento’s architecture and makes your store’s navigation more user-friendly.

If you’re looking for additional guidance on Magento theme development or customization services, feel free to reach out to our team at Laravel Company. We specialize in providing high-quality development solutions tailored to your specific needs.

Catalog Extensions Themes Errors

Our network