kreativmonkey Posted August 28, 2015 Share Posted August 28, 2015 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 More sharing options...
Martijn Geerts Posted August 28, 2015 Share Posted August 28, 2015 it's ->getRandom() with an a no e 3 Link to comment Share on other sites More sharing options...
tpr Posted August 28, 2015 Share Posted August 28, 2015 Thet meid my dey! Link to comment Share on other sites More sharing options...
kreativmonkey Posted August 28, 2015 Author Share Posted August 28, 2015 that is embarrassing to me.... and I have been working for over an hour on it and have not seen it. Sorry and Thanks a lot! Link to comment Share on other sites More sharing options...
adrian Posted August 28, 2015 Share Posted August 28, 2015 that is embarrassing to me.... and I have been working for over an hour on it and have not seen it. Sorry and Thanks a lot! Don't ba amberressad - it heppans to avaryona, avan us netiva Anglish spaekars 2 Link to comment Share on other sites More sharing options...
tpr Posted August 28, 2015 Share Posted August 28, 2015 So true! WillyC bein the only exception Link to comment Share on other sites More sharing options...
Macrura Posted August 28, 2015 Share Posted August 28, 2015 interesting to read about aliases for functions function getRendom() { getRandom(); } php 5.6+ use function getRandom as getRendom; Link to comment Share on other sites More sharing options...
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