Skip to main content

Simple Rotating Block Content

There are a number of solutions available for management of content display within a block, creating slideshows, tabs, etc. Sometimes a simple rotating message is needed, and can be accomplished with a few lines of code. This example has 4 quotes with css classes that can be further styled in the theme's css.

One of the pre-requisites for entering php code into blocks is enabling PHP filter in admin/build/modules and setting appropriate user permissions. Once in the block edit mode, be sure to choose PHP code as the Input Format.

$quotes[] = "<div class=\"front-quote-text\">Text1.</div>";
$quotes[] = "<div class=\"front-quote-text\">Text2.</div>";
$quotes[] = "<div class=\"front-quote-text\">Text3.</div>";
$quotes[] = "<div class=\"front-quote-text\">Text4.</div>";

srand ((double) microtime() * 1000000);
$randomquote = rand(0,count($quotes)-1);
echo "<div id=\"front-quote\">";
echo $quotes[$randomquote];
echo "</div>";

Share this post