Make Pagelist go random

Permalink
Hello!

First of all, happy easter for those that celebrate this holiday.

Then my question: I have a pagelist and I would like to make this list at a random order. It now gives me the oppertunity to list it by alphabetical and such.

Can anyone tell me what I have to change to get this to work?

(The reason for this is that I show 3 'icons' but there are actually 5 icons and I want it to display it at a different order every time.)

I'd love a reply, thanks!

View Replies:
C5LABS replied on at Permalink Reply
C5LABS
consider using shuffle function .
http://php.net/manual/en/function.shuffle.php...
JohntheFish replied on at Permalink Reply
JohntheFish
See:

http://www.concrete5.org/community/forums/customizing_c5/page-list-...

and also may be relevant:
http://www.concrete5.org/community/forums/customizing_c5/random-pag...

If you want to search further, as C5 labs has noted 'shuffle' is the function usually used and seacrhing on 'shuffle' brings up plenty of others who have solved this.

http://www.concrete5.org/community/forums/-/view/?sort=relevance&am...
mkly replied on at Permalink Reply
mkly
I don't know if those articles talk about this, but the biggest problem I run into with this is eating up large amounts of memory.

Typically I end up indexing it and grabbing the five pages after. Because you are going to eat 64MB after 45-50 pages, which isn't so hot if you have more than 4 people checking out your site.

In general PageList is a memory murderer, which I think is because of the Page object includes everything from the get go instead of an on demand behavior.

$number_of_results = 5;
$pl = new PageList();
$pl->filterBySomething('blah');
// So we get the total returned and base off that
$total = $pl->getTotal() - 1;
$count = 0;
// This is our hand made "page list"
$pages = array();
// This is just to make sure we stay unique
$selected_indexes = array();
// Loopin - the $count <= $total is to make sure we
// Don't loop forever if there are less returned
// then number of results we want
while($count <= $total && count($pages) <= $number_of_results) {
  $index = rand(0, $total);