Magento

eCommerce Software for Online Growth

Simple random banner rotator in Magento using static blocks

1.SomeBannerIdentifierName_1
2.SomeBannerIdentifierName_2
3.SomeBannerIdentifierName_3
4....
5.SomeBannerIdentifierName_N

For each content use this:

Some alt text

Please note that you are not restricted only to images, you could use text, video or whatever you want here, but I’ll focus on images with links as title says.

Now when all is set, make new file called banner_rotator.phtml in “/app/design/frontend/YOUR_INTERFACE/YOUR_THEME/template/callouts/banner_rotator.phtml”

And use this code inside:

< ?php
echo $this->getLayout()->createBlock(’cms/block’)->setBlockId(’SomeBannerIdentifierName_’.mt_rand(1, N))->toHtml() ?>

*Make sure you replace “N” with highest number of your static block

In order to show this block, you should be familiar with Magento layouts.
Since that is out of scope for this article, I’ll show you how to put it below the content on cms pages.

Open “/app/design/frontend/YOUR_INTERFACE/YOUR_THEME/layout/cms.xml”

[*] Put this line:

P U T [*] H E R E ! ! !

ref: http://inchoo.net/ecommerce/magento/simple-random-banner-rotator-in-magento-using-static-blocks/


© Copyright 2010 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
177719 users|1143 users currently online|277257 forum posts