To display number of product that is associated to the particular category I have overrided a magento Navigation Block. for that I have create a very small extension code. please check it down.
create a xml file at app/etc/modules/Prakash_All.xml and copy/paste following code
<config>
<modules>
<Prakash_Catalog>
<active>true</active>
<codePool>local</codePool>
</Prakash_Catalog>
</modules>
</config>
Then create another xml file in exact following path and name
app/code/local/Prakash/Catelog/Block/etc/config.xml and copy/paste following code in this file
<config>
<modules>
<Prakash_Catalog>
<version>0.1.0</version>
</Prakash_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<navigation>Prakash_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
</global>
</config>
This code rewrite the existing Navigation Block with our custom navigation. Even though we have to change just a few code it is always better to to write in our own custom rewrite module.
and then create another files with name and location as app/code/local/Prakash/Catelog/Block/Navigation.php
and copy/paste following code
class Prakash_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation
{
protected function _renderCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false,
$isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false)
{
if (!$category-&gt;getIsActive()) {
return '';
}
$html = array();
// get all children
if (Mage::helper('catalog/category_flat')-&gt;isEnabled()) {
$children = (array)$category-&gt;getChildrenNodes();
$childrenCount = count($children);
} else {
$children = $category-&gt;getChildren();
$childrenCount = $children-&gt;count();
}
$hasChildren = ($children &amp;&amp; $childrenCount);
// select active children
$activeChildren = array();
foreach ($children as $child) {
if ($child-&gt;getIsActive()) {
$activeChildren[] = $child;
}
}
$activeChildrenCount = count($activeChildren);
$hasActiveChildren = ($activeChildrenCount &gt; 0);
// prepare list item html classes
$classes = array();
$classes[] = 'level' . $level;
$classes[] = 'nav-' . $this-&gt;_getItemPosition($level);
if ($this-&gt;isCategoryActive($category)) {
$classes[] = 'active';
}
$linkClass = '';
if ($isOutermost &amp;&amp; $outermostItemClass) {
$classes[] = $outermostItemClass;
$linkClass = ' class="'.$outermostItemClass.'"';
}
if ($isFirst) {
$classes[] = 'first';
}
if ($isLast) {
$classes[] = 'last';
}
if ($hasActiveChildren) {
$classes[] = 'parent';
}
// prepare list item attributes
$attributes = array();
if (count($classes) &gt; 0) {
$attributes['class'] = implode(' ', $classes);
}
if ($hasActiveChildren &amp;&amp; !$noEventAttributes) {
$attributes['onmouseover'] = 'toggleMenu(this,1)';
$attributes['onmouseout'] = 'toggleMenu(this,0)';
}
// assemble list item with attributes
$htmlLi = '&lt;li';
foreach ($attributes as $attrName =&gt; $attrValue) {
$htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
}
//count product for first category
$productCount = '';
$catRef = Mage::getModel('catalog/category')-&gt;load($category-&gt;getId());
$productCount = ' '.$catRef-&gt;getProductCount().' ';
$htmlLi .= '&gt;';
$html[] = $htmlLi;
$html[] = '&lt;a href="'.$this-&gt;getCategoryUrl($category).'"'.$linkClass.'&gt;';
$html[] = '&lt;span&gt;' . $this-&gt;escapeHtml($category-&gt;getName()).$productCount . '&lt;/span&gt;';
$html[] = '&lt;/a&gt;';
// render children
$htmlChildren = '';
$j = 0;
foreach ($activeChildren as $child) {
$htmlChildren .= $this-&gt;_renderCategoryMenuItemHtml(
$child,
($level + 1),
($j == $activeChildrenCount - 1),
($j == 0),
false,
$outermostItemClass,
$childrenWrapClass,
$noEventAttributes
);
$j++;
}
if (!empty($htmlChildren)) {
if ($childrenWrapClass) {
$html[] = '&lt;div class="' . $childrenWrapClass . '"&gt;';
}
$html[] = '&lt;ul class="level' . $level . '"&gt;';
$html[] = $htmlChildren;
$html[] = '&lt;/ul&gt;';
if ($childrenWrapClass) {
$html[] = '&lt;/div&gt;';
}
}
$html[] = '&lt;/li&gt;';
$html = implode("\n", $html);
return $html;
}
public function renderCategoriesMenuHtml($level = 0, $outermostItemClass = '', $childrenWrapClass = '')
{
$activeCategories = array();
foreach ($this-&gt;getStoreCategories() as $child) {
if ($child-&gt;getIsActive()) {
$activeCategories[] = $child;
}
}
$activeCategoriesCount = count($activeCategories);
$hasActiveCategoriesCount = ($activeCategoriesCount &gt; 0);
if (!$hasActiveCategoriesCount) {
return '';
}
$html = '';
$j = 0;
foreach ($activeCategories as $category) {
$html .= $this-&gt;_renderCategoryMenuItemHtml(
$category,
$level,
($j == $activeCategoriesCount - 1),
($j == 0),
true,
$outermostItemClass,
$childrenWrapClass,
true
);
$j++;
}
return $html;
}
}
Here we have just added one line of code from existing Navigation.php block of Magento code but I hope that it will be helpful to all of you.
Please download full code from following location
Navigation
Download from github repository:
https://github.com/phpprakash/navigation