Recently I set up a site that features people in a short article. These people are displayed on an overview page, and the order is shuffled as follows:
foreach($page->children()->visible()->shuffle() as $p
This is to avoid people at the bottom getting less views than those up top.
But now it’s difficult for visitors to navigate the website. Every time they open the overview the people are re-shuffled, and keeping track of which people they have viewed is difficult, even with a :visited state.
I was wondering if I could shuffle the pages once, and then save that order for the remainder of the session or a different timeframe (e.g. shuffle order once per day).
The best I can come up with is to shuffle and then set a cookie, and not shuffle again if that cookie is set. But that only leaves me with a default sorting order, rather than a randomized one (so bottom people will still get less views).
if(isset($_COOKIE['shuffle'])):
foreach($page->children()->visible()->shuffle() as $p) :
...
endforeach
else:
foreach($page->children()->visible() as $p) :
...
endforeach
setcookie('shuffle', 'shuffle', time() + (86400), "/");
endif
If I could pass a seed, variable or timecode to the shuffle function which would always end up with the same order for that seed, that would solve this problem, but as far as I know this isn’t possible.
I know I can reorder them manually in panel but there’s about 50 people with more people being added weekly so it would be somewhat tedious.