Magento: Display Category Image by ID in CMS page

Magento: Display Category Image by ID in CMS page

July 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Display Category Image by ID in CMS page

Displaying Category Image by ID in Magento CMS Page

As a senior developer working extensively with e-commerce platforms like Magento, I often receive queries regarding customizing storefront displays. One common question is how to display a specific category image directly within a CMS page using the category’s ID.

Understanding the Default Magento Functionality

By default, Magento allows you to display a category link or its products by referencing the category ID in your CMS content. However, it does not provide a built-in widget or block type for displaying just the category image.

Here are the default possibilities:

  1. Category Link: You can create a link to the category using its ID.

    {{widget type="catalog/category_widget_link" anchor_text="Displayed Text" title="Title attribute text" template="catalog/category/widget/link/link_block.phtml" id_path="category/22"}}
    
  2. Category Products: You can display a list of products from the category using its ID.

    {{block type="catalog/product_list" category_id="14" template="catalog/product/list.phtml"}}
    

Displaying Category Image Using Custom Code

To achieve this, we’ll need to leverage custom code or a third-party extension. Here’s a common approach using a bit of PHP and the Magento API:

  • First, you need to create a new file in your CMS page template directory (usually app/design/frontend/your_package/your_theme/template/page/cms/index.phtml).

  • In this new file, use the following code snippet to get the category image by ID:

    $category = Mage::getModel('catalog/category')->load(123); // Replace with your category ID
    if ($category->getImage()) {
        $imageUrl = Mage::helper('catalog/image')->init($category, 'image')->resize(300);
        echo '<img src="' . $imageUrl . '" alt="' . $category->getName() . '" />';
    }
    

Integrating Custom Code with CMS Page

To use this custom code in your CMS page:

  1. Create a new static block using Magento’s CMS system (System > Configuration > Design > HTML Head > Miscellaneous Scripts).

  2. Add the path to your new PHP file as a script, for example: app/design/frontend/your_package/your_theme/template/page/cms/index.phtml.

  3. Save the configuration.

  4. Now you can reference this new static block in any CMS page using the following code:

    {{block type="cms/static_block" block_id="category_image_block"}}
    

Conclusion

While Magento does not provide a built-in way to display a category image by ID within a CMS page, we can achieve this through custom PHP code and the Magento API. By following the steps outlined above, you can easily incorporate category images into your store’s content.

Remember, before making any changes to core files or creating custom PHP scripts, always backup your data and make sure the site is in maintenance mode to prevent conflicts during the update process.

If you’re looking for more advanced Magento customization services or need a team of experts to handle your e-commerce development needs, I recommend checking out our range of services at LaravelCompany. Our seasoned developers are ready to assist with projects of any scale.

Happy coding!

Catalog API Extensions Themes

Our network