Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Need help with IF statement

 

 


sublmnl
User

Feb 22, 2011, 1:11 PM

Post #1 of 6 (1102 views)
Shortcut
Need help with IF statement Can't Post

Reaching out to the board once again.
Thanks for all the previous help!.

Lets say I have two linked images by each entry.
Maybe some entries only have one link/image but not both and other entries have both links/images. The images are the same for everyone (facebook, twitter icons) so the echo works well here. I may even have some entries that have no linked images.

I want to show the image only if the client puts a link for it in the CMS.

So something like this but need PHP to get it done.
---
If link in CMS, then show image
If no link in CMS then skip and move onto the next image and check for link.
If no links, then don't show images at all.



Makes sense?


gkornbluth
Veteran

Feb 22, 2011, 7:35 PM

Post #2 of 6 (1094 views)
Shortcut
Re: [sublmnl] Need help with IF statement [In reply to] Can't Post

Makes great sense.

Here's an approach that might help.

I used it in my foreach loop to display a Facebook image as a link, only if the client entered a Facebook URL in the "facebook" field of the record.

The preg_match part of the code makes sure that an http:// is added to the URL if necessary:


Code
<?php if ($record['facebook']): ?> 
<?php if (!preg_match("/^http:\/\//", $record['facebook'])) {$record['facebook'] = "http://" . $record['facebook']; }
?>

<a class="alphabet" href="<?php echo $record['facebook'] ?>" target="_blank"> <img src="images/Facebook_icon.gif" alt="Facebook Logo" vspace="5" width="32" height="32" /></a>
<?php endif ?>


NOTE: You might want to implement the free removeExtraWhitespace plugin that Dave Edis created http://www.interactivetools.com/forum/gforum.cgi?post=84270;search_string=removeExtraWhitespace;#84270
to insure that an errant blank space doesn't trick the if statement into showing the image.

There's a lot more about working with if statements in my CMSB Cookbook http://www.thecmsbcookbook.com

Hope that get's you started.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!
http://www.thecmsbcookbook.com


sublmnl
User

Feb 23, 2011, 10:08 PM

Post #3 of 6 (1061 views)
Shortcut
Re: [gkornbluth] Need help with IF statement [In reply to] Can't Post

Works Jerry. Thanks and I have your online book. I should refer to it more often.

Below is my code that I have with that works:


Code
<?php foreach ($featuredRecords as $record): ?> 
.....
....
....
...

<?php if ($record['event_venue_facebook_link']): ?><?php if (!preg_match("/^http:\/\//", $record['event_venue_facebook_link'])) {$record['event_venue_facebook_link'] = "http://" . $record['event_venue_facebook_link']; }
?><a href="<?php echo $record['event_venue_facebook_link'] ?>" target="_blank"><img src="/images/facebook_small22.png" /></a><?php endif ?><?php if ($record['event_venue_twitter_link']): ?><?php if (!preg_match("/^http:\/\//", $record['event_venue_twitter_link'])) {$record['event_venue_twitter_link'] = "http://" . $record['event_venue_twitter_link']; } ?><a href="<?php echo $record['event_venue_twitter_link'] ?>" target="_blank"><img src="/images/twitter_small22.png" /></a><?php endif ?>

<?php endforeach ?>



gkornbluth
Veteran

Feb 24, 2011, 5:15 AM

Post #4 of 6 (1048 views)
Shortcut
Re: [sublmnl] Need help with IF statement [In reply to] Can't Post

Glad you got it going.

Jerry
The first CMS Builder reference book is now available on-line!
http://www.thecmsbcookbook.com


sublmnl
User

Dec 11, 2011, 12:12 PM

Post #5 of 6 (525 views)
Shortcut
Re: [gkornbluth] Need help with IF statement [In reply to] Can't Post

Reaching out for a little more help on this one but with a twist this time.
I love the 'If Link' thing we did earlier.... but what I want to do this now:

IF (checkbox) is Yes
Then show _link

I'm talking about the '_link' that is created from the list page to a detail page.
In my list record editor, I have a field that is a checkbox

Code
<?php echo $record['has_a_page'] ?>

I only want to show the "_link" to the detail page if the checkbox is checked. I was going to wrap the <?php echo $record['title'] ?> with the IF ELSE statement because if the checkbox is not checked I still want to show the unlinked <?php echo $record['title'] ?> but I got stumped on this one.
Help?!


(This post was edited by sublmnl on Dec 11, 2011, 12:40 PM)


Jason
Staff / Moderator


Dec 11, 2011, 9:59 PM

Post #6 of 6 (512 views)
Shortcut
Re: [sublmnl] Need help with IF statement [In reply to] Can't Post

Hi,

Try this:


Code
 
<?php if ($record['has_a_page']):?>
<a href = "<?php echo $record['_link'];?>"><?php echo $record['title'];?></a>
<?php else:?>
<?php echo $record['title']; ?>
<?php endif ?>


Does this seem to be what you're looking for?

Hope this helps
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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