- This topic is empty.
-
AuthorPosts
-
October 14, 2012 at 8:51 pm #40291slb535Member
Here’s my code. In case it isn’t obvious what I’m trying to do, I want to only show the image if there is info in the field. And the link around the image uses the info in the field. The mailto: is coming up blank. So I’m guessing/hoping I’m doing something wrong with the way I’m printing/calling it. I would greatly appreciate any help.
if ( $email ) { ?>
“>October 14, 2012 at 10:27 pm #111847pmac627ParticipantTry this:
$email = types_render_field (“email”);
if (!empty($email)) {
?>
“>http://php.net/manual/en/function.empty.php
isset might work better for you.EDIT: Also, your $empty variable right after the mailto is missing a semicolon. ;)
October 14, 2012 at 11:26 pm #111849slb535MemberThanks for looking at this.
knocks it out of the HTML it’s in. So instead of an image wrapped in a URL, I get
[email protected]"> IMAGE
pmac627, your solution doesn’t work for me either. I still get a blank value for my string. And I’ve tested other fields, to make sure it isn’t just this field. I will look into isset though. Thanks for the recommendation.
October 15, 2012 at 8:29 am #111868pmac627ParticipantPerhaps try echo $email; instead? Good call, @traq. I can’t believe I missed that as well.
Try to echo $email somewhere on the page to make sure that it actually contains a value.
October 15, 2012 at 9:38 am #111879VermaasParticipantThis will do the trick:
Don’t know why the markup of this is so shit. But copy it in your code and make it look more nice.
` // Get the e-mail variable
$email = types_render_field (“email”);// Print out the e-mail variable, to make sure you’ve got one
echo “" . print_r($email) . "
“;
// Check for an e-mail address
if ( !empty($email) ) { ?>
“>
October 16, 2012 at 9:35 pm #112027slb535MemberNope, I’ve tried echo before. It does the same thing as print — knocks it out of the href link and displays it on the page.
And Vermaas, unless I’m missing something, yours is the same as pmac627 with just the print_r ($email) to test the content of the string. Am I getting that wrong?
I’m hoping to have this site online for testing in a few days. Perhaps I can post a link then and get your thoughts.
Again, thanks for trying.
October 16, 2012 at 10:13 pm #112029slb535MemberI figured it out! It had to do with the way the custom field had been created. When it was an “email field”, it gave me that big mess. When I made it just a single line text field, it was fine.
Thank you all for your help. (Especially since I was missing that echo in addition to everything else.)
AuthorPostsViewing 7 posts - 1 through 7 (of 7 total)- The forum ‘Back End’ is closed to new topics and replies.