TransWikia.com

How to display subcategories on category page?

Magento Asked by Sanya Zahid on January 30, 2021

I have used this code in view.phtml to display subcategories on category page

<?php foreach ($this->getCurrentCategory()->getChildrenCategories() as $_subcat): ?>
    <li><a href="<?php echo $_subcat->getUrl() ?>"><?php echo Mage::helper('catalog/output')->categoryAttribute($_subcat, $_subcat->getName(), 'name') ?></a></li>
<?php endforeach ?>

but this is obviously displaying only the list of subcategories, I want image and same view as products on category page

Desired Result

enter image description here

Getting this

enter image description here

Favorite community please help 🙂

2 Answers

Use below code

$_category = Mage::registry('current_category');

$subcategories = Mage::getModel('catalog/category')->getCategories($_category->getId());


foreach ($subcategories as $subcategory){ ?>
    <li><a href="<?php echo $subcategory->getUrl() ?>"><?php echo $subcategory->getName() ?></a></li>
<?php }

Answered by Akhil Gupta on January 30, 2021

Try to make a var dump of "$_subcat" inside the foreach:

<?php foreach ($this->getCurrentCategory()->getChildrenCategories() as $_subcat): ?>
    <?php var_dump($_subcat->getData()); die(); ?>
<?php endforeach ?>

You will display all the options available to use.

Answered by Andrea Rivadossi on January 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP