Peter Knight Posted December 7, 2018 Posted December 7, 2018 Someone suggested that an easy way to output a random image from a field was to use getRandom and then simply use limit=1 I'm not sure where I apply it to the following <?php $randomitem = $pages->get(1034)->images->getRandom(); foreach($randomitem as $item) { echo " <img src='{$item->url}' class='squares'> ";} ?> Does it go at the start where I define my variable or somewhere in the echo statment? Thanks
dragan Posted December 7, 2018 Posted December 7, 2018 https://processwire.com/api/ref/wire-array/get-random/ Quote If one item is requested (default), the item is returned (unless $alwaysArray argument is true). If multiple items are requested, a new WireArray of those items is returned. 1
Peter Knight Posted December 7, 2018 Author Posted December 7, 2018 Quote // Get a single random item $randomItem = $items->getRandom(); Got it. Thanks @dragan too
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