So in Magento they use php to dynamically call the product categories in the left menu. However, some categories are empty as of right now and I want to use code pull the category count and only display categories with product in them, but if product is added later, the code will allow the category to be displayed. It should be easy but I am not a php coder. I have pasted the code which calls the categories and an article that explains how to this knowing the category ids, but i want it to be dynamic. Any help would be greatly appreciated! http://prattski.com/2008/12/17/magento-display-only-if-there-are-products-in-the-category/ <?php /** * Magento Enterprise Edition * * NOTICE OF LICENSE * * This source file is subject to the Magento Enterprise Edition License * that is bundled with this package in the file LICENSE_EE.txt. * It is also available through the world-wide-web at this URL: * http://www.magentocommerce.com/license/enterprise-edition * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category design * @package enterprise_default * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) * @license http://www.magentocommerce.com/license/enterprise-edition */ ?> <?php /** * Category left navigation * * @see Mage_Catalog_Block_Navigation */ ?> <?php if (!Mage::registry('current_category')) { return; } $_categories = $this->getCurrentChildCategories(); $_count = is_array($_categories)?count($_categories):$_categories->count(); ?> <?php if($_count): ?> <div class="block block-layered-nav"> <div class="block-title"> <h2><?php echo $this->__('Browse By') ?></h2> </div> <div class="block-content"> <dl> <dt><?php echo $this->__('Category') ?></dt> <dd> <ol> <?php foreach ($_categories as $_category): ?> <?php if($_category->getIsActive()): ?> <li> <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() ?>) </li> <?php endif; ?> <?php endforeach ?> </ol> </dd> </dl> </div> </div> <?php endif; ?> PHP:
Replace: <?php if($_category->getIsActive()): ?> PHP: with this: <?php if($_category->getIsActive() && $_category->getProductCount() > 0): ?> PHP: And now it should only render categories which have products in it.
If any Question About php and other development So please Connect here OR Visit hare webxtechnology.com Thanks