Grow your CSS skills. Land your dream job.

Calling a string in a link

  • # October 14, 2012 at 8:51 pm

    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.

    < ?php $email = types_render_field ("email");
    if ( $email ) { ?>
    “>

    # October 14, 2012 at 10:27 pm

    Try this:

    < ?php
    $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:09 pm

    Also, `< ?php $email ?>` doesn’t work (unless you have some reallyold/reallyfunky configuration). It needs to be either:

    `< ?php print $email; ?>`

    or

    `< ?= $email ?>`
    (works ONLY IF short_open_tag is enabled, or with PHP 5.4.)

    # October 14, 2012 at 11:26 pm

    Thanks for looking at this.

    < ?php print $email; ?> knocks it out of the HTML it’s in. So instead of an image wrapped in a URL, I get
    person@emailaddress.com"> 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

    Perhaps 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

    This 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.

    `< ?php
    // 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

    Nope, 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

    I 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.)

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".