Saturday, November 26, 2011

How to add featured product in magento

This tutorial will show you how to implement a featured products. First you have to create the static block using magento admin panel and then include this static block into the magento. There are different ways we can add static blocks. yet another attempt to explain with quick and easy examples.
Example 1: how to include static block in phtml file?
Let us suppose, you have created static block with identifier “promo_block” in magento admin.
Now, you can call the static block from any phtml file with the help of following code:

echo $this->getLayout()->createBlock('cms/block')->setBlockId('promo_block')->toHTML();
Example 2: How to include static block on product view page?
We will refer the same static block “promo_block”. Now open “catalog.xml” file from current theme folder ( and search for string “”.
You can add following code just before closing tag of product view page. we are adding “promo_block” static block into right reference. However you can add this block into any area like “content”, “left”, etc
  1. <reference name="right">  
  2.     <block type="cms/block" name="promo_block" as="promo_block">  
  3.        <action method="setBlockId"><block_id>promo_blockblock_id>action>  
  4.     block>  
  5. reference>  
Share this nice post:

No comments: