I work with an organization that consists of a number of different ships. On one of the pages of the site the ships were listed in alphabetical order and the captains wanted their listings to appear randomly on the page so that every ship has more fair immediate visibility.
I dug for 5 hours on Concrete5's site looking for guidance from other developers who may have tried to help someone with this same need and in the end, I found 1 "How-to" and one forum post, the combination of which (after tweaking both sets of codes) I got it to do exactly what I wanted!
We work with Concrete 5.6.3 and "Scrapbooks" have been replaced with "Stacks"
I created a new stack called "Ships" and within this stack I created 8 separate HTML blocks which contained the HTML code for each captain's listing.
I found the PHP code for randomizing blocks from the related How-to mentioned here posted by Marticps back in April 2012.
I installed the Simple PHP Block Add-on, which is free.
I created a new page and in the "Add to Main" area, I added a new PHP block.
Within that PHP block, I added the code snippet here:
$st = Stack::getByName('YOUR STACK NAME');
$page = Page::getCurrentPage();
$pageid = $page->getCollectionID();
if ($pageid == YOUR PAGE ID) {
$area= new Area('Main');
$blocks = $st->getBlocks('Main');
shuffle($blocks);
foreach ($blocks as $b){$b->display();}
}
else {
$area= new Area('Main');
$area->display($c);
}
Please note that the previous how-to instructions from April 2012 were a bit sparse and failed to mention that you SHOULD NOT include the starting and ending PHP pieces (). The Simple PHP Block is just that, a block, and it produced errors if you try to embed the opening and closing php code in it.
This solution works like a dream and did exactly what I wanted it to do:
- It reaches inside a defined stack,
- Pulls out the individual block components,
- And then randomizes those blocks on the page so that each time you hit refresh, all the blocks appear in a different order.
I wanted to share this with you all in the hopes that it may help someone else! :-)