Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged


I gave up on this in the end and requested the client manually add the placeholder image when creating the post. Thank you all for your contributions.


Another idea is to initialize an $image variable earlier in your script like so: $image = $item->image ? $item->image : 'images/placeholder.jpg'; The $image will get the value of the $item->image if it's set, or the placeholder file path you set. Then you use the $image variable in place of the $item->image in your script. *You won't need the ...


Your are missing brackets around else: <?php if ($item->image) { ?> ... <?php } else { ?> ... <?php } ?> You may also give alternative syntax a try, see if it's more readable to you: <?php if ($item->image) : ?> ... <?php else : ?> ... <?php endif; ?>

Top 50 recent answers are included