Search This Blog

Aug 30, 2011

Magento: How to Display Subcategory image

In magento file system, editing the category pages can be accomplish by navigating to the category phtml file. It's file directory is somewhat like this:


NOTE: Please take note to replace you’re the packagename and themename that you are using.

To display the category image for both parent and children category you can try the following code on the phtml I’ve mentioned above.

$_category  = $this->getCurrentCategory(); 
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id); //Get the current category and its children

foreach ($collection as $category){ //Loop through the categories
    $subCategory = Mage::getModel('catalog/category')->load($category->getId()); 
//Get the child category models
    $imgSrc = $subCategory->getImageUrl(); //Get the image url
        echo '<img src="'.$imgSrc.'" />'; //Echo  the image

The above code will loop on each current category and display the image corresponds to it.


Magento Developer said...

This works great for mw

Anonymous said...

great solution, well done!