Rotating/Cycling image links

Permalink 1 user found helpful
I have nearly 50 image links (thumbnail + text label) that I need to arrange in rows of about 4 per row. I need these to randomise or pseudo-randomise so that image links at the bottom of the page get a fair crack of the whip and get up the top sometimes. Not an uncommon need.

I thought I had cracked it with "Stack Randomiser" so I created stacks Row1, Row2 etc with 4 thumbnails in each stack and set the stack to appear randomly on a page. No good, of course! ... I could end up with 12 rows of all the same stack given that it's random.

Sticking with the 'stacks of 4 images' approach, how could I pseudo-randomise the display of thumbnails such that on any refresh of the page each thumb only displays once, ie each stack/row is displayed in a different position each time?

A slideshow is not on as I want all the images to be on display all the time.

Thanks

Robert

 
ramonleenders replied on at Permalink Reply
ramonleenders
You are probably better off creating ONE block where you enter all links (or image links, not sure what they are) and randomise them within this same block. When randomised, divide them into seperate rows of 4. Now loop the rows and display them. That's what you want.

Like you said, with multiple stacks you could have double ones and the system wouldn't really know. Also, as a stack is pre configured, the position of 1,2,3 and 4 are always the same. The solution above I proposed, hasn't got this pattern so it's always random.

In conclusion, I do not think that what you want is something that is on the marketplace, and has to be created (custom) for you.
JohntheFish replied on at Permalink Reply
JohntheFish
If pre 5.7:

Take the List FIles From Set addon and insert a shuffle() for the array of files. The standard addon simply lists files, or I have some image list templates that show thumbnails.

Both are free in the marketplace.

If you want more control, many variations of such would be easy to set up with Uber List and Magic Data.
mesuva replied on at Permalink Reply
mesuva
I'll add here that there are both 5.6 and 5.7 versions of the List Files From Set block in the marketplace - both should pretty much be the same to create a custom template for where the images it fetches can be shuffled before output.
Robert12345 replied on at Permalink Reply
Hello

You have all been very helpful and encouraged me to look around the C5 site a bit more. I readhttp://www.concrete5.org/documentation/how-tos/developers/how-to-ex... [if this doesn't show as a link, my apologies].

As mentioned previously I had a test stack containing 4 blocks,each a thumbnail and a line of text underneath. With the above How-To I installed the Simple PHP Block and entered the following php therein:

$st = Stack::getByName('row1');
   $page = Page::getCurrentPage();
   $pageid = $page->getCollectionID();
   if ($pageid == 149) { 
   $area= new Area('Main');
   $blocks = $st->getBlocks('Main');
   shuffle($blocks);
   foreach ($blocks as $b){$b->display();}
   }
   else {
    $area= new Area('Main');
    $area->display($c); 
    }


My only variables I changed to the code are the name of my stack (row1) and the ID of my page (gained via Edit | Properties whilst on that particular page) - in this case 149.

The code pulls the individual blocks from the stack that they are part of and displays them randomly.

In practice my page is slightly more complex in that it is displaying them as part of a portfolio page design within a particular theme, but the procedure of pulling a block out and displaying randomly within the structure one has setup seems pretty sound ... so far! :-)

Thanks for you encouragement and taking the time to comment. thanks to mwac5 who posted the code and to his orig source Marticps.

Robert