0

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 2

0

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.

1
  • 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" } Commented May 4, 2017 at 10:37
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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