Magento – Magento: How to add two or more static Blocks on category page

cmsmagento-1.8static-block

I am creating category page and i want to add two static blocks to it. While I was going through CMS/Static Blocks, I realized I can Only add One Static Block to any page. I couldn't find anything where i can add 2 or more static blocks. Is there a way i can add two or more such static blocks in a single category page.

Best Answer

You can add any number of static blocks in any page in anywhere as you desire.

Since you need to add two static blocks.. create two static blocks through admin.(CMS -> Static Blocks). Let the identifiers used for two static blocks be mystaticblock_1 and mystaticblock_2. Then you can use following code directly in your page (phtml file) in order to display your static block

  <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('mystaticblock_1')->toHtml() ?> 
  <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('mystaticblock_2')->toHtml() ?> 

You can also add static blocks through your layout file. An example is shown below

<handler_correspond_to_desired_page>
<reference name="content">
    <block type="cms/block" name="my_staticblock_1">
        <action method="setBlockId"><block_id>mystaticblock_1</block_id></action>
    </block> 
    <block type="cms/block" name="my_staticblock_2">
        <action method="setBlockId"><block_id>mystaticblock_2</block_id></action>
    </block> 
</reference>
</handler_correspond_to_desired_page>

Then go to the template file where you need to display the static block and add the following code in the appropriate location

<?php echo $this->getChildHtml('my_staticblock_1') ?>
<?php echo $this->getChildHtml('my_staticblock_2') ?>

There is lot of tutorials regarding this topic. Please make a ruff idea about static blocks and their usages. Good luck