Magento random block generator / block randomiser

This could be pretty useful if you want to combine XML block control with a random content display (eg. banner ads).
Very easily achieved, simply create 1 file in ./base/default/template/page/html/random_block.phtml
<?php $children = $this->getSortedChildren(); if(is_array($children)) { shuffle($children); echo $this->getChildHtml($children[0]); } ?>Then in your relevant XML file - control the output by using:
<block type="core/template" name="left.callout.random" template="page/html/random_block.phtml" before="-">
<block type="core/template" name="left.callout.random1" template="callouts/left_col.phtml">
<action method="setImgWidth"><width>240</width></action>
<action method="setImgSrc"><src>images/image1.png</src></action>
<action method="setImgAlt" translate="alt" module="catalog"><alt>some alt text</alt></action>
<action method="setLinkUrl"><url>link url</url></action>
</block>
<block type="core/template" name="left.callout.random2" template="callouts/left_col.phtml">
<action method="setImgWidth"><width>240</width></action>
<action method="setImgSrc"><src>images/image2.png</src></action>
<action method="setImgAlt" translate="alt" module="catalog"><alt>some alt text</alt></action>
<action method="setLinkUrl"><url>link url</url></action>
</block>
</block>
You can add any type of block you want and it will just grab one at random.
[syntaxhighlighter]