Here is a quick and complete code to load parent category from current category page and to get sub categories of parent category along with their product count.
if (is_object(Mage::registry('current_category'))) { |
$parentCategory = Mage::getModel('catalog/category')->load(Mage::registry('current_category')->getId())->getParentCategory(); |
$parentCategory = Mage::getModel('catalog/category')->load($rootCategoryId); |
$_categories = $parentCategory->getChildrenCategories(); |
$productCollection = Mage::getResourceModel('catalog/product_collection'); |
$productCollection->addCountToCategories($_categories); |
foreach ($_categories as $_category): |
if($_category->getIsActive()): |
<a href="<?php echo $_category->getUrl() ?>"> |
<?php echo Mage::helper('core')->htmlEscape($_category->getName()) ?> |
<?php echo '('.$_category->getProductCount().')'; ?> |
Hope it helps. Thanks.
|
No comments:
Post a Comment