Show Image if URL is entered

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

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

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