Random Dynamic Page button.

So to give context: I want to create a website where you press a button. And every time you press it, a random video popps up, with a headline and a description explaining it.

SO, going through this amazing forum I’ve managed to create a database with all the content, and create dynamic pages designed in the way I want them to be displayed.

To the problem: Now I need a button, that when clicked, displays a random Dynamic page.

I have had a bunch of theories in how this could be done, in which I tried many, in which none have worked.

Any ideas how I could make this vision a reality?

Thanks.

Hi David!

A great idea!
I would start from arranging the data in an array and shuffle it (make it random).
You can find a snippet for a shuffling function here .

Secondly, depending on if you want repeats or not, I would suggest to add a boolean field that will indicate if the page was visited or not (and mark it when it does).

Now, as for the button, it should first get all the data from the collection using query and then apply the shuffling function on the returned data.
Take the first option from the returned array (data[0]) and save it as your target URL*.

*If you’d like no repeats, before redirecting the page check if the boolean flag (that I mentioned before) is set to false - which means the page hasn’t been visited.

Hope it helps!
Best of luck.

Doron. :slight_smile:

Heeey Doron!

Thanks for answering, I’ve tried to understand it but I’m a bit lost, my coding skills are very limited.
Do you think you could dumb it down a little?

This is what I got. A working dynamic page that loads information from my Collection successfully, I also have a button that through the connection options can help me go to the next dynamic page.

Really, all I want now, Is for that button. Instead of sending me to the next dynamic page when clicked. Send me to a Random one.

hehe, sorry for being slow, thanks a lot for the answer!

Hi David,
In your case a few method are need.
wixLocation.to , wixData.query and the shuffling function as Doron suggested above.
Add an onClick event to the button as explained here .
Use the examples in the references.
Feel free to paste your code here.
Roi.

Heey guuuys, I’m really appreciating the help and I don’t doubt you’re on to something! However, I don’t really get what you’re saying at all… This is what I get.
I get that the OnClick action means that when you click the button this code will be executed:


Soooo, I understand that in the stuff that you sent me, there is some sort of code combination that would make the dynamic pages to appear randomly.
And I’m sure it’s awesome stuff It’s just that I don’t get it (I’ve really tried to decipher it).

Is there any example code that I could insert that would make the magic happened?

Best
I-have-no-clue-what-I’m-doing

Is this possible yet?

Is this possible yet?