Displaying Category Image in navigation menu in magento

Displaying Category Image in navigation menu in magento

September 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Displaying Category Image in navigation menu in magento

Displaying Category Image in Navigation Menu in Magento

Hello developers! Today we’re going to tackle an interesting challenge in Magento - displaying category images directly in your navigation menu.

As you’ve discovered, the default drawItem function in Magento only displays the name of each category when looped through in a navigation menu. However, with a bit of tweaking, we can easily pull out and display the image URL associated with each category.

Understanding the Category Image URL

First, let’s understand where Magento stores the category image URL. When you upload an image for a category from the admin panel, Magento actually saves this as a base64 encoded string in the catalog_category_entity_varchar table under the image column for that particular category.

The image is not physically stored anywhere on your server; it’s embedded directly into the database to improve performance. This is why you need a special method to retrieve and display these images.

Retrieving the Category Image URL

To retrieve the image URL, we can use Magento’s built-in getImageUrl method for the category model. However, this method only works with product images by default. For category images, we need to add an additional parameter false.

Here’s how you can modify your existing code:

<?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php echo $this->drawItem($_category) ?>

    <!-- Note the false added here -->
    <?php echo Mage::getModel('catalog/category')->load($_category->getId())->getImageUrl(false) ?>

    <?php endforeach ?>

The false parameter in getImageUrl(false) tells Magento to load the image from the database instead of a physical file on your server.

Displaying the Category Image

Now, let’s create an HTML img element to display this image. We’ll add this directly inside the li element generated by drawItem:

<?php foreach ($this->getStoreCategories() as $_category): ?>
    <li class="level0 nav-1" id="nav-<?php echo $_category->getId() ?>"><?php echo $this->drawItem($_category) ?></li>

    <!-- Note: Added the image element here -->
    <img src="<?php echo Mage::getModel('catalog/category')->load($_category->getId())->getImageUrl(false); ?>" alt="<?php echo $_category->getName() ?>" width="50" height="50">

<?php endforeach ?>

In this example, we’re displaying the image with a fixed size of 50x50 pixels. The actual size is not important; what matters is that the src attribute contains the correct base64 encoded URL.

Conclusion

And there you have it! With these changes, your category images should now display correctly in the navigation menu generated by getStoreCategories.

Remember, this method is specific to Magento 1.x. In Magento 2, the process involves using the catalogcategoryimages table and a slightly different approach, which I’ll cover in another post.

If you’re looking for more advanced techniques or need help with other aspects of your Magento store, feel free to check out LaravelCompany, where we provide comprehensive guides on e-commerce development.

Catalog Database Performance API

Our network