Jump to content

getRendom() Image Problem


kreativmonkey
 Share

Recommended Posts

Hi,

i like to display rendom images from pages to my sidebar, now i give up and ask you!

Thats my Code, i have create with the results of my searches:

$pagesWithImages = wire('pages')->find("images.count>0, template=post, limit=10, sort=rendom");
     $out = "<div class='sidebar gallery'><h3><i class='fa fa-picture-o'></i> Gallery</h3><div class='row'>";

     foreach($pagesWithImages as $p){
       if(!count($p->images)) continue;
       $pageUrl = $p->httpUrl;
       $pageTitle = $p->title;
       $images = $p->images->getRendom();
       $out .= "<div class='col-md-4 col-sm-6 col-xs-6'><a href='$pageUrl'><img class='img-responsive' src='{$images->size(80,80)->url}' alt='$pageTitle'/></a></div>";

     }

return $out .'</div></div>';

at the first line i wont to get all pages with images inside put that dosn't work, i become a lot of pages without images...

so i test for images at the loop, that works!

In the loop i get informations from the page and now the problem, i wont to get a rendom image from the image array (the output formatting is alway an array!!) and than i call this image to the ->size() function!

Fatal error: Call to a member function size() on a non-object in /processwire/site/templates/_init.inc on line 172

i don't know what i have to do! print the array i loop the array, i do a lot of things but always the same error massage that i try to call a member function on a non-object! But there is an object and the cheatcheet says "Returns a single random item from this WireArray." that sounds to me like to get $image->first() but not the first one but rendom!

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...