Peter Knight

apply limit to random

Recommended Posts

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

Share this post


Link to post
Share on other sites
Quote

// Get a single random item
$randomItem = $items->getRandom();

Got it. Thanks @dragan too

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.