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)

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

By Jason - April 21, 2010

Hi,

It's not a bad solution. You could trim it down a bit like this:

<?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 break ?>
<?php endif ?>
<?php endforeach ?>
<?php if (!$record['photographs'): ?>
<a href="<?php echo $record['_link'] ?>"><img src="/assets/th-no-image.png" width="85" height="60" border="0"></a>
<?php endif ?>


The other thing I noticed is you're using <?php break ?>. If there are images uploaded, only the first one will be displayed as the break command will end the foreach loop. If you want to display all of the images that have been uploaded, just remove that line.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

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.