I have multiple items in my content file. The first item is placed in a foreach loop, the remaining items are placed in a separate foreach loop, like this:
This works properly in that the first item always gets placed in the first loop, but what I’d actually like is to choose a random item and place that in the first loop.
So when the page loads, item number 4 gets randomly picked, separated from the rest and placed only in the separate, first loop. When the page loads again, a different item number gets randomly picked, and so on.
Thanks, I’ve already tried (a way more complicated and unnecessary piece of) code using “not”, but it gave back an error, as does your piece of code. When I include the third line (otherItems) I get:
Illegal offset type in unset, in /kirby/vendor/getkirby/toolkit/lib/collection.php.
/**
* Returns a new collection without the given element(s)
*
* @param args any number of keys, passed as individual arguments
* @return Collection
*/
public function not() {
$collection = clone $this;
foreach(func_get_args() as $kill) {
unset($collection->data[$kill]);
}
return $collection;
}