Jump to content

Using getRandom(x)


Jim Yost
 Share

Recommended Posts

Hi,

I am trying to return 3 random images from an image field using getRandom(3). It appears to be returning all 6 results. I do have only 6 images uploaded to the field.

<?php
$images = $page->images->getRandom(3);
foreach($images as $image)
{
    $thumbnail = $image->size(118,112);
    echo "<a href='{$image->url}'><img class='photo' src='{$thumbnail->url}' alt='{$image->description}' /></a>";
}

I initially thought it was a problem with WireArray, however the following works as expected.

<?php
$test_pages = $pages->get("/")->children->getRandom(3);
foreach($test_pages as $test) {
    echo $test->name . "<br />";
}

Any ideas?

-Jim

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...