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 :)


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.

  • not working <br> array(7) { ["entity_id"]=> string(2) "46" ["name"]=> string(2) "LG" ["path"]=> string(12) "1/2/14/45/46" ["is_active"]=> string(1) "1" ["is_anchor"]=> string(1) "0" ["request_path"]=> string(36) "tv-and-home-theater/shop-by-brand/lg" ["id"]=> string(2) "46" } – Sanya Zahid May 4 '17 at 10:37

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 }
  • not working :/ ... – Sanya Zahid May 4 '17 at 11:49
  • Try using direct category ID instead: $_category->getId() – Akhil Gupta May 5 '17 at 4:35
  • still getting names only, i want images – Sanya Zahid May 5 '17 at 7:26
  • For image use: <img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'. $subcategory->getThumbnail(); ?>" alt="" /> inside foreach loop – Akhil Gupta May 5 '17 at 8:54
  • ibb.co/cpBFkk – Sanya Zahid May 5 '17 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.