Display placeholder image if no image uploaded, on list view

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 21, 2010   (RSS)

By (Deleted User) - April 21, 2010 - edited: April 21, 2010

Hi,

Just wondering if there was a better way to do this.

Pretty standard lister, listing all the properties meeting search criteria.

Properties can have 0-5 pictures uploaded. If 0 pictures loaded, display a placeholder image

<?php $hasimage = 0 ?>
<?php foreach ($record['photographs'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>"
alt="" width="<?php echo $upload['thumbWidth'] ?>"
height="<?php echo $upload['thumbHeight'] ?>" border="0" /></a><br/>
<?php $hasimage = 1 ?>
<?php break ?>
<?php endif ?>
<?php endforeach ?>
<?php if ($hasimage == 0): ?>
<a href="<?php echo $record['_link'] ?>"><img src="/assets/th-no-image.png" width="85" height="60" border="0"></a>
<?php endif ?>


This works, just wondering, is there a better (more elegant) way to do it.

I tried using sizeof(), but if there is no image loaded, it just gives an error.

Re: [Jason] Display placeholder image if no image uploaded, on list view

By (Deleted User) - April 21, 2010

Hi,

Yah, I need the break - only one image is required [;)]

I like the (!$record['photographs'): ?> code tho'. I definitely can see using a similar construction that in a few other places.