davo Posted May 18, 2014 Share Posted May 18, 2014 I'm still learning the api and came across this issue. Maybe it's the bbq and beers that's clouded my head but here it is: $testimonial_image_pages = $pages->find("parent=1088");foreach ($testimonial_image_pages as $testimonial_image_page) { echo "{$testimonial_image_page->images->first()->url}";} You can probably see what i'm trying to do. I have a number of pages and I just want to use the 1 and only image on each of those pages to ultimately display in an img tag. I just get this back: Error: Call to a member function getRandom() on a non-object (line 222 of /var/www/clients/client2/web37/web/site/templates/home.php) Link to comment Share on other sites More sharing options...
davo Posted May 18, 2014 Author Share Posted May 18, 2014 hold that... beer is starting to wear off and i'm see sense. Link to comment Share on other sites More sharing options...
adrian Posted May 18, 2014 Share Posted May 18, 2014 Well you might have already sorted it out, but it's hard for us to help without seeing the section of code that contains the getRandom(). This should work: echo $testimonial_image_page->images->getRandom()->url; If it doesn't and you get the same error, then please check to make sure that the template of these pages has a field called "images". Link to comment Share on other sites More sharing options...
davo Posted May 18, 2014 Author Share Posted May 18, 2014 Well you might have already sorted it out, but it's hard for us to help without seeing the section of code that contains the getRandom(). This should work: echo $testimonial_image_page->images->getRandom()->url; If it doesn't and you get the same error, then please check to make sure that the template of these pages has a field called "images". Your hunch was right. I'd called the images a totally different field name.. of course it was never going to work! solved like this: $testimonial_image_pages = $pages->find("parent=1088, Testimonial_image>1, limit=6"); $testimonial_image_pages->shuffle(); foreach ($testimonial_image_pages as $testimonial_image_page) { echo "<div class='col-md-2'><a href='testimonial-types/testimonials-from-event-companies/'><img class='img img-responsive' src='{$testimonial_image_page->Testimonial_image->url}'></a></div>"; } 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