Magento Use Product Image Thumbnails in the CMS Pages and Static Blocks
Sep 8, 2010 · 1 minute readCategory: magento
Pretty standard requirement - using product images in CMS sections, however you may find yourself including static HTML references to product images - and if you are using resized images then you might hardcode in links to cached images, which is obviously going to break at some point, or you painstakingly download copies of product images and reupload them for use in the CMS - but then they might go out of date.
This is the real solution:
Create a new template file in {template}/catalog/product/cms_image.phtml
Put these contents
<?php
$productId = $this->getProduct_id();
$_product = Mage::getModel('catalog/product')->load($productId);
$imageSize = $this->getImage_size();
?>
<img src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize($imageSize, $imageSize); ?>"
alt="<?php echo $this->htmlEscape($_product['name']); ?>" border="0" width="<?php echo $imageSize;?>" />
- Use this snippet in your CMS content (changing product_id and image_size accordingly) ```
{{block type=“catalog/product_view” product_id=“1752” image_size=“135” template=“catalog/product/cms_image.phtml”}}
```