Show Image if URL is entered

5 posts by 3 authors in: Forums > CMS Builder
Last Post: June 3, 2013   (RSS)

By csdesign - May 31, 2013

Hello! 

I'm doing a sidebar specific to each lodge page (lodges are entered as multiple record and these options are part of a single lodge entry page where all info for that specific lodge is loaded).  In the sidebar, I would like each image to appear IF something is entered into the field.  If it's blank - I'd like the image to be hidden.

See Sidebar on right side of page (planning guide, tours, facebook, online rez) 
http://www.yellowstone-lodging.com/lodges-east-yellowstone-detail.php?Absaroka-Mountain-Lodge-2

<table width="226" border="0" cellspacing="0" cellpadding="0">                   <tr>                     <td height="25" align="center" valign="middle">&nbsp;</td>                   </tr>                   <tr>                     <td align="center" valign="middle"><img src="images/seclodge-planning-guide-travel.png" alt="Get our vacation planning guide" width="128" height="128" /></a></td>                   </tr>                   <tr>                     <td align="center" valign="middle"><img src="images/seclodge-sidebar-div2.png" width="226" height="13" vspace="15" /></td>                   </tr>                   <tr>                     <td align="center" valign="middle"><a href="<?php echo htmlencode($lodge_pagesRecord['360_tour_link']) ?>"><img src="images/lodge-bnr-360-tours.png" alt="360 pano photos tours" width="158" height="67" vspace="4" /></a></td>                   </tr>                   <tr>                     <td align="center" valign="middle"><img src="images/seclodge-sidebar-div2.png" width="226" height="13" vspace="15" /></td>                   </tr>                   <tr>                     <td align="center" valign="middle"><a href="<?php echo htmlencode($lodge_pagesRecord['facebook_url']) ?>" target="_blank"><img src="images/like_us_on_facebook.png" alt="Like us on facebook!" width="158" height="60" vspace="10" /></a></td>                   </tr>                   <tr>                     <td align="center" valign="middle"><img src="images/seclodge-sidebar-div2.png" width="226" height="13" vspace="15" /></td>                   </tr>                   <tr>                     <td align="center" valign="middle"><a href="<?php echo htmlencode($lodge_pagesRecord['online_reservations_url']) ?>" target="_blank"><img src="images/seclodge-online-reservations.jpg" alt="Make your vacation reservations online" width="143" height="149" /></a></td>                   </tr>                   <tr>                     <td align="center" valign="middle"><img src="images/seclodge-sidebar-div2.png" width="226" height="13" vspace="15" /></td>                   </tr>                                    </table>  

I had used this code previously but I'm not sure if this is exactly what I'm trying to do... although I'm sure it's very close - with some rearranging, of course: 

<?php foreach ($listingRecords as $record): ?>  
<?php if ($record['banner_status'] == 'Sold') : ?><img src="http://www.domain.com/images/bnr-sold.jpg" width="312" height="25" /><?PHP endif ?>  
<?php if ($record['banner_status'] == 'Reduced') : ?><img src="http://www.domain.com/images/bnr-reduced.jpg" width="312" height="25" /><?PHP endif ?>  
<?php if ($record['banner_status'] == 'New') : ?><img src="http://www.domain.com/images/bnr-new-listing.jpg" width="312" height="25" /><?PHP endif ?>
 <?php endforeach ?> 

Thank you! Tina

By gkornbluth - June 1, 2013

Hi Tina,

Entered by the user on the web page or entered in the cms record?

Jerry Kornbluth

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

By ross99 - June 1, 2013

Hi Tina

Thanks for posting! Your code looks good to me :).  There are slight more advanced ways you could do what you are doing but what you have should work great :).  The difference between what you have and the more advanced way is one less line of code and I don't think it's worth the time investment for such a small return.

Have you actually tried the code you posted on the page you linked us to?  What happens when you do?  Let me know :).

Thanks!

Ross Fairbairn
http://www.interactivetools.com
consulting@interactivetools.com

By gkornbluth - June 3, 2013

Hi Tina,

To test for the existence of something in a field (not its specific value) you can just delete the == '???'

from an if statement

If you get errors when there's nothing in the field, insert an @ sign before $record. That will suppress errors from being generated.

<?php if (@$record['planning_guide_pdf']) : ?>

Best,

Jerry Kornbluth

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