Product Count Per Category in Magento


<ul>              
  <?php $id = 42;?>
  <?php $cat = Mage::getModel('catalog/category')->load($id);?>
  <?php $subcats = $cat->getChildren();?>
  <?php foreach(explode(',',$subcats) as $subCatid):?>
  <?php $_category = Mage::getModel('catalog/category')->load($subCatid);?>
  <?php if($_category->getIsActive()):?>  
  <?php $productCount = Mage::getModel('catalog/category')->load($_category->getId())->getProductCount();?>

 <li><a href="<?php echo $_category->getURL();?>"><span><?php echo $_category->getName();?><?php echo '('.$productCount.')'?></span></a></li>

<?php endif;?>
<?php endforeach;?>
</ul>

 

Copyright @ 2014 HK Magento Blog.