Swap for generic image if no upload
3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 24, 2008 (RSS)
Hi all,
I thought that this one would be simple but I’m stuck again...
I’ve set up a listing page for a series of publicity articles.
http://janstein.com/publicity2.php
In the code below, if the publicity article is only an external link, then that article’s listing is formatted as a link. If the article’s contents is stored in the record, then that article’s listing links to the detail page for that record. So far this works fine.
The listings also show a thumbnail if a listing_page_image is uploaded for that record.
I’m trying to get a generic image to show if there’s no listing_page_image uploaded (as in article 2 on the sample page).
No matter what I’ve tried, this part won’t work. No errors, but the generic image doesn’t even show in the page’s source code.
Anybody see what I’ve missed?
Thanks
Jerry Kornbluth
I thought that this one would be simple but I’m stuck again...
I’ve set up a listing page for a series of publicity articles.
http://janstein.com/publicity2.php
In the code below, if the publicity article is only an external link, then that article’s listing is formatted as a link. If the article’s contents is stored in the record, then that article’s listing links to the detail page for that record. So far this works fine.
The listings also show a thumbnail if a listing_page_image is uploaded for that record.
I’m trying to get a generic image to show if there’s no listing_page_image uploaded (as in article 2 on the sample page).
No matter what I’ve tried, this part won’t work. No errors, but the generic image doesn’t even show in the page’s source code.
Anybody see what I’ve missed?
Thanks
Jerry Kornbluth
<table width="90%" border="0" align="center" cellpadding="5">
<tr>
<td valign="top"><div align="center" class="Medium-Text" >CLICK BELOW TO<br />
LEARN MORE </div></td>
<td valign="top"> </td>
</tr>
<!-- If the article is only an external link, show it as a link -->
<?php foreach ($publicityRecords as $record): ?><tr>
<?php if ($record['article_link_url']): ?><td width="25%" valign="middle"><div align="center">
<a href="<?php echo $record['article_link_url'] ?>">
<?php foreach ($record['listing_page_image'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<!-- If there is no listing_page_image uploaded, show the generic image -->
<?php else: ?>
<img src="http://www.janstein.com/images/JS-NEWS.png" width="150" height="103" alt="News Article" />
<?php endif ?>
<?php endforeach ?></a> </div>
</td>
<td width="75%" valign="middle"><div class="Medium-Text-Bold"><a href="<?php echo $record['article_link_url'] ?>"><?php echo $record['listing_page_title'] ?></a></div>
<div class="Medium-Text"><?php echo $record['listing_page_sub_title'] ?></div></td>
<!-- If the article's contents is stored in the description field of the record, show the detail page with the article’s contents -->
<?php elseif ($record['description']): ?>
<td width="25%" valign="middle">
<div align="center"><a href="<?php echo $record['_link'] ?>">
<?php foreach ($record['listing_page_image'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<!-- If there is no listing_page_image uploaded, show the generic image -->
<?php else: ?>
<img src="http://www.janstein.com/images/JS-NEWS.png" width="150" height="103" alt="News Article" />
<?php endif ?>
<?php endforeach ?></a></div>
</td>
<td width="75%" valign="middle">
<a class="Medium-Text" href="<?php echo $record['_link'] ?>"><strong><?php echo $record['listing_page_title'] ?></strong><br /><?php echo $record['listing_page_sub_title'] ?></a></td>
<?php endif ?>
</tr> <?php endforeach ?>
</table>
The first CMS Builder reference book is now available on-line!
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Swap for generic image if no upload
By Dave - November 24, 2008
Hi Jerry,
If there are no images, the code in the foreach loop will never run - since it runs one 'for each' image. So what you need to do is put it below like this:
Let me know if that works for you.
If there are no images, the code in the foreach loop will never run - since it runs one 'for each' image. So what you need to do is put it below like this:
<?php foreach ($record['listing_page_image'] as $upload): ?>
...
<?php endforeach ?>
<?php if (!$record['listing_page_image']): ?>
No images found (or show default image)
<?php endif ?>
Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com
interactivetools.com
Re: [Dave] Swap for generic image if no upload
By gkornbluth - November 24, 2008 - edited: November 25, 2008
It seems the learning curve is filled with hairpin turns...
After beating on it with my big programming hammer for a while based on your direction, It's now working fine.
Thanks Dave for all your help
After beating on it with my big programming hammer for a while based on your direction, It's now working fine.
Thanks Dave for all your help
The first CMS Builder reference book is now available on-line!
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php