Hello!
I have tried multiple solutions to get the subcategory thumbnails but all failed.
I want to iterate them in my index page NOT in a category page. I think that's the key to my problem.
Getting subcategory names and urls was quite fine but the thumbnail info is not getting there or I dont know how to get it.
Please help if possible, I have tried like 10 or more solutions and getting hopeles and tired
My category structure is/will be following
Root category
Category1
Subcategory1 - need url, thumbnail img, name
Subcategory2
Subcategory3
...
Category2
Subcategory1
Subcategory2
...
Regards,
Kaia
Solved! Go to Solution.
This is what finally helped me to have thumbnail images in my index page. I hope it can help some newbie like me
<div class="product-categories"> <div class="block "> <div class="block-content"> <div class="custom-static1"> <div class="row"> <?php $_helper = Mage::helper('catalog/category') ?> <?php $_categories = $_helper->getStoreCategories() ?> <?php if (count($_categories) > 0): ?> <?php foreach ($_categories as $_category): ?> <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()); ?> <?php $_subcategories = $_category->getChildrenCategories() ?> <?php if (count($_subcategories) > 0): ?> <?php foreach ($_subcategories as $_subcategory): $subcatId = $_subcategory->getId(); $_cat = Mage::getModel('catalog/category')->load($subcatId);?> <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6"> <div class="wapper"> <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"> <div class="image pull-right"> <div class="img-overlay"> <img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$_cat->getThumbnail()?>" alt=""> </div> </div> <div class="pull-left"> <h3> <span class="categories-title"> <?php echo $_subcategory->getName() ?> </span> </h3> </div> </a> </div> </div> <?php endforeach; ?> <?php endif; ?> <?php endforeach; ?> <?php endif; ?> </div> <div class="clear clr"></div> </div> </div> </div> </div>
You can try this :
<?php foreach ($this->getCurrentCategory()->getChildrenCategories() as $_subcat): ?> $_subcat->getThumbnailImageUrl()
OR
$_subcat->getImageUrl(); <?php endforeach; ?>
Sadly not working, I am currently having this code that gives me all subcategory data except for the the correct thumbnails.
<?php $_helper = Mage::helper('catalog/category') ?> <?php $_categories = $_helper->getStoreCategories() ?> <?php if (count($_categories) > 0): ?> <ul> <?php foreach ($_categories as $_category): ?> <li> <a href="<?php echo $_helper->getCategoryUrl($_category) ?>"> <?php echo $_category->getName() ?> <img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$_category->getThumbnail()?>" alt=""> </a> <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?> <?php $_subcategories = $_category->getChildrenCategories() ?> <?php if (count($_subcategories) > 0): ?> <ul> <?php foreach ($_subcategories as $_subcategory): ?> <li> <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"> <?php echo $_subcategory->getName() ?> <img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$_subcategory->getThumbnail()?>" alt=""> </a> </li> <?php endforeach; ?> </ul> <?php endif; ?> </li> <?php endforeach; ?> </ul> <?php endif; ?>
This is what finally helped me to have thumbnail images in my index page. I hope it can help some newbie like me
<div class="product-categories"> <div class="block "> <div class="block-content"> <div class="custom-static1"> <div class="row"> <?php $_helper = Mage::helper('catalog/category') ?> <?php $_categories = $_helper->getStoreCategories() ?> <?php if (count($_categories) > 0): ?> <?php foreach ($_categories as $_category): ?> <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()); ?> <?php $_subcategories = $_category->getChildrenCategories() ?> <?php if (count($_subcategories) > 0): ?> <?php foreach ($_subcategories as $_subcategory): $subcatId = $_subcategory->getId(); $_cat = Mage::getModel('catalog/category')->load($subcatId);?> <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6"> <div class="wapper"> <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"> <div class="image pull-right"> <div class="img-overlay"> <img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$_cat->getThumbnail()?>" alt=""> </div> </div> <div class="pull-left"> <h3> <span class="categories-title"> <?php echo $_subcategory->getName() ?> </span> </h3> </div> </a> </div> </div> <?php endforeach; ?> <?php endif; ?> <?php endforeach; ?> <?php endif; ?> </div> <div class="clear clr"></div> </div> </div> </div> </div>