Hi, sometimes you will need to show the area blocks of a page in a random order. To do that, we will get the blocks of the area and shuffle them. Then we will display every block. We will do this only if the page is not in edit mode, so when you enter edit mode you can edit the page normally. Copy this code in the place you want to show the blocks in your theme file (replace the area code that should go if we want to show the blocks normally).
<?php
$area= new Area('Your Area');
if ($c->isEditMode()) {
$area->display($c);
} else {
$blocks = $page->getBlocks('Your Area');
shuffle($blocks);
foreach ($blocks as $b){$b->display();}
}
?>
In some occasions we will need to do this only in a page, not in all the pages that contain the area. The first thing we need to do is to get the ID of the page where we want to show the blocks. To do that you have to go to the properties of your page and, next to the page name, you'll find the page id. Then, the code should be the following:
<?php
$page = Page::getCurrentPage();
$pageid = $page->getCollectionID();
if ($pageid == XXX) { //Replace XXX for the ID of your page
$area= new Area('Your Area');
if ($c->isEditMode()) {
$area->display($c);
} else {
$blocks = $page->getBlocks('Your Area');
shuffle($blocks);
foreach ($blocks as $b){$b->display();}
}
} else {
$area= new Area('Your Area');
$area->display($c);
}?>
That's all. Easy, right? Hope it has been useful to you, marticps.
PS: Sorry for my english :P