a-ok Posted November 15, 2017 Posted November 15, 2017 Hi folks hope all is well. I'm wanting to insert a random repeater row into a page selector loop ($pages->find()) at a random point (after the 1st, after the 5th, after the 2nd – different each reload). I have managed to get a random repeater row and now I need to insert it into my returned pages... $ctas = $pages->get("name=site-settings")->settings_ctas; $cta = $ctas->getRandom(); $events = $pages->find("template=events-detail, events_detail_dates.events_detail_dates_start_date>=today, sort=events_detail_dates.events_detail_dates_start_date, sort=name"); // Return in-date events only I thought about using $a->insertAfter($item, $existingItem) and setting $existingItem to a random integer? Is this is the best way do you reckon? http://cheatsheet.processwire.com/pagearray-wirearray/setting-and-modifying-items/a-insertafter-item-existingitem/
a-ok Posted November 15, 2017 Author Posted November 15, 2017 Actually what I ended up doing was this... $random = $articles->getRandom(); if ($article == $random) { ... Seemed to work pretty well.
Sergio Posted November 15, 2017 Posted November 15, 2017 You can add the random repeater to the $events array and shuffle it after that. $events->append($cta); $events->shuffle(); Sorry, I just saw that you are ordering the events. So this will not work. In this case I think using insertAfter() is a good solution. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now