List subcategories with product count Magento

<?php
$_helper = $this->helper(‘catalog/output’);
$_subcategories = $blockId = Mage::getModel(‘catalog/layer’)->getCurrentCategory()->getChildrenCategories();
?>
<div class=”block block-layered-nav”>
<div class=”block-content”>
<dl id=”narrow-by-list”>
<?php if(! empty($_subcategories)): ?>
<dt>Category</dt>
<dd>
<ol>
<?php foreach($_subcategories as $subCategory) : ?>

<?php $prodCollection = Mage::getResourceModel(‘catalog/product_collection’)->addCategoryFilter($subCategory); // Magento product collection ?>
<li><a href=”<?php echo $subCategory->getUrl(); ?>”><?php echo $subCategory->getName(); ?></a>
(<?php echo $prodCollection->count(); ?>)</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
</dd>

</dl>
</div>
</div>

Share