0

I am trying to display my subcategories in a grid with respective images on my homepage. I got everything workin but the images. What am I missing? the link to the page is colagenosnella.com.br, Code follows. Thank in advance.

<?php
/*
* http://fishpig.co.uk - Magento Tutorials
*
* Display top level categories and subcategories
*
**/
?>
<?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 $_subcategory->getImageUrl() ?>" width="200" height="200" />
                                <?php echo $_subcategory->getName() ?>
                            </a>

                    <?php endforeach; ?>

            <?php endif; ?>

    <?php endforeach; ?>
0

I don't see any source in your image tag when visiting your site. For example on the first sub-category you are displaying "Beleza Da Pele" the source shows;

<img src(unknown) width="200" height="200">

Looking at your code and testing it myself on a development site I see that the method getImageUrl() does not return anything. I believe this is to do with the method you are using to retrieve the collection of categories: 'getChildrenCategories()' from the Mage_Catalog_Model_Category class.

According to the question here; that method will only retrieve the sub-category's name, urlKey, children and is_anchor attributes.

In short I believe you need to use a different method to initially retrieve your categories or if you are not confident find a good tutorial. From the code you have supplied I see it is from FishPig, who are good but I suspect you may be reading an outdated post.

Best of luck.

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.