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 csdesign - June 3, 2013 - edited: June 3, 2013

Then entry would be via the cms admin. For example. 

If a lodge  has an online reservation link, I would enter that url in the field in the admin.  If no url is entered, the "online reservations" graphic would NOT appear on the detail page. If a url IS entered, then the "online reservations" graphic WOULD appear on the detail page and contain the hyper link to the url that was entered. 

The part I wasn't sure about was how to convert that code I had for "Sold, Reduced & new banners" over to what I need... but here's a shot. I replaced Sold, reduced and new with "???" because that's the part I don't understand. I believe the rest is correct.  Hopefully :)   On the first one. I have the option of uploading a single pdf file or entering a url link - either way, the image showing on the page remains the same. .  The rest are a single entry - either a url is entered - or it is not.  

<?php foreach ($lodge_pagesRecords as $record): ?>  

<?php foreach ($lodge_pagesRecord['planning_guide_pdf'] as $index => $upload): ?>
<?php if ($record['planning_guide_pdf'] == '???') : ?><a href="<?php echo $upload['urlPath'] ?>" target="_blank"><img src="images/seclodge-planning-guide-travel.png" alt="360 pano photos tours" width="128" height="128" vspace="4" /></a><?PHP endif ?>
<?php endforeach ?>

<?php if ($record['planning_guide_link'] == '???') : ?><?php echo htmlencode($lodge_pagesRecord['planning_guide_link']) ?>" target="_blank"><img src="images/seclodge-planning-guide-travel.png" alt="360 pano photos tours" width="128" height="128" vspace="4" /></a><?PHP endif ?>  

<?php if ($record['facebook_url'] == '???') : ?><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><?PHP endif ?>  

<?php if ($record['360_tour_link'] == '???') : ?><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><?PHP endif ?>

<?php if ($record['online_reservations_url'] == '???') : ?><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><?PHP endif ?>

<?php endforeach ?> 

Thanks guys!!!  Your help is greatly appreciated!!  Tina