BFD Calendar Posted November 28, 2014 Share Posted November 28, 2014 I'm trying to show an image on a page. There are three possibilities 1. get an image from the page, 2. if there isn't any, get an image from an image_url textfield on the page, 3. and if there isn't any, get a random image from the homepage. It seems I'm missing something in my 'if elsif else' logic.... Only the image from the page - if there is one - shows up, nothing else. if($page->bfd_people_picture) { $images = $page->bfd_people_picture->getRandom(2); foreach($images as $image) { $thumbnail = $image->width(300); echo "<div id='images'><img class='photo' src='{$thumbnail->url}'></div>"; } } elseif($page->bfd_image_from_url) { $webimage = $page->bfd_image_from_url; echo "<div style='max-width:300px'><img src='{$webimage}' align='right' style='width:100%; height:100%' /></div>"; } else { $homeimage = $homepage->images->getRandom()->width(300); echo "<div id='images'><img class='photo' src='{$homeimage->url}'></div>"; } Link to comment Share on other sites More sharing options...
kongondo Posted November 28, 2014 Share Posted November 28, 2014 Use count() to check if images present in a multiple images field...http://processwire.com/api/fieldtypes/images/ (it's an array). Otherwise it always returns true.. if(count($page->bfd_people_picture)) 1 Link to comment Share on other sites More sharing options...
BFD Calendar Posted November 28, 2014 Author Share Posted November 28, 2014 Use count() to check if images present in a multiple images field...http://processwire.com/api/fieldtypes/images/ (it's an array) Ah, I guess when desperate one probably forgets to look in the first place where one should look.... Link to comment Share on other sites More sharing options...
kongondo Posted November 28, 2014 Share Posted November 28, 2014 The link was meant to point you to more info . No problem with asking (especially if you've already attempted to solve the problem) . Is your question resolved then? Link to comment Share on other sites More sharing options...
BFD Calendar Posted November 28, 2014 Author Share Posted November 28, 2014 Yes it works, and the link was helpful. It was also helpful as I said because it reminded me to look where I probably should have looked in the first place: the image field stuff. But I was too much fixed on the if elsif else stuff because I had that working somewhere else already. 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