Get category image in Magento

By | October 19, 2013

It is a very simple and easy way to get a category image in Magento.
If you want to show the current category image in Magento, Please use following code given below:

1
2
$category = Mage::getModel('catalog/layer')->getCurrentCategory(); 
$img = $this->getCategoryImage($category); // call a function

Please create a function as given below:

1
2
3
4
5
6
7
8
9
10
11
12
13
function getCategoryImage($category) 
{
    $categoryCollection = Mage::getModel('catalog/category')
                        ->setStoreId(Mage::app()->getStore()->getId())
                        ->getCollection()
                        ->addAttributeToSelect('image')
                        ->addIdFilter($category->getId());

    foreach($categoryCollection as $category) 
    {
        return $category->getImageUrl();
    }
}

Leave a Reply