Product count in Magento layered category navigation
I'm new to Magento and I can't work out how to display the number of products in a category in the category list efficiently. I've done it by hacking _renderCategoryMenuItemHtml on the instance of Mage_Catalog_Block_Navigation but it's a stupid hacky solution.
All I want is something like:
- Product (1)
- P开发者_Python百科roduct (4)
- Product (50)
I've read stuff about /app/design/frontend/default/theme_name/template/catalog/layer/filter.phtml but after adding it to my theme no edits seem to make any effect. I have also tried editing the default and blank versions and no luck. Any suggestions?
You can echo the product count by using this:
echo $_category->getProductCount()
You can add this code to your template (depending on which template you have, mine is rightnav.phtml) in app/frontend/default/YOUR TEMPLATE/catalog/navigation/TEMPLATE NAME.PHTML
example:
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this- >isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->htmlEscape($_category->getName()) ?></a> <?php echo $_category->getProductCount() ?>
getProductCount method gets all products number that assigned to that category(not checks is_active or is_in_stock etc.)
精彩评论