0

I am trying to display my subcategories images on my home page with the following code:

<?php
/**
* http://fishpig.co.uk - Magento Tutorials
* Display top level categories and subcategories
**/
$_helper    = $this->helper('catalog/output');
$_category  = $this->getCurrentCategory();    
?>
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>

<?php if (count($_categories) > 0): ?>

    <?php foreach($_categories as $_category): ?>


            <div style="float: left; padding-right: 18px; ">    

            <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
            <?php $_subcategories = $_category->getChildrenCategories() ?>
            <?php if (count($_subcategories) > 0): ?>

                    <?php foreach($_subcategories as $_subcategory): ?>

                            <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                            <img src="<?php echo $_category->getImageUrl() ?>" width="200" height="200" />

                            </a>

                    <?php endforeach; ?>

            <?php endif; ?>

    <?php endforeach; ?>

But the image shows the parent category instead, can be seen in www.colagenosnella.com.br. Any Thoughts? Thanks in advance.

  • Do you want to show only the parent level categories or subcategories of a specific category? – Sukumar Gorai Jun 11 '18 at 7:35
0

Use below foreach loop

<?php foreach($_categories as $_category): ?>


            <div style="float: left; padding-right: 18px; ">    

            <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
            <?php $_subcategories = $_category->getChildrenCategories() ?>
            <?php if (count($_subcategories) > 0): ?>

                    <?php foreach($_subcategories as $_subcategory): ?>

                        <?php $_category = Mage::getModel('catalog/category')->load($_subcategory->getId()) ?>

                            <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                            <img src="<?php echo $_category->getImageUrl() ?>" width="200" height="200" />

                            </a>

                    <?php endforeach; ?>

            <?php endif; ?>

    <?php endforeach; ?>

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.