• Resolved starscr3am

    (@starscr3am)


    I know this can be done because I manged it on an old blog I used to have, but stupidly I deleted all the theme files and I can’t remember how to do this anymore.

    What I want to do is link to other websites from my blog posts using custom fields. I also want each link to display as an image that will be in my “uploads” folder.

    Not every post will need to link to an outside website so I don’t want the link image to be present on posts that I don’t have any links on.

    So far I’m having no luck hiding the image on posts with no links. Any help would be greatly appreciated.

    At the minute I’m using this code…

    <a href="<?php $key="CUSTOM FIELD"; echo get_post_meta($post->ID, $key, true); ?>"><img class="aff" src="IMAGE LOCATION" /></a>

    but the image shows up on every post, link or no link.

    Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)
  • If custom field is present, formulate and display link from meta value

    <?php
    $link = get_post_meta($post->ID, 'link_url', true);
    $text = get_post_meta($post->ID, 'link_text', true);
    if ($link){
    echo 'Credit: <a href="'.$link .'">'.$text.'</a>';
    }
    ?>

    Thread Starter starscr3am

    (@starscr3am)

    I tried using that code and it keeps giving me an error message.

    Last time I did it I used a similar code to the one I’m using now but with a little bit added to only show fields that had values. I just can’t remember what the extra code was

    Then review Custom Fields.

    Thread Starter starscr3am

    (@starscr3am)

    I figured it out.

    <?php if ( get_post_meta($post->ID, 'CUSTOM-FIELD', true) ) { ?><a href="<?php echo get_post_meta($post->ID, "CUSTOM-FIELD", $single = true); ?>"><img src="IMAGE-LOCATION" /></a><?php } ?>

    That seems to work for me

    starscr3am
    that works good ! for text too ??

    BIG thanks

    <?php if ( get_post_meta($post->ID, ‘CUSTOM-FIELD’, true) ) { ?>Your text: <?php echo get_post_meta($post->ID, “CUSTOM-FIELD”, $CUSTOM-FIELD = true); ?><?php } ?>

    you get

    Your text: custom field value

    How to hide custom field output if the field is left empty on submition

    the field is not required

    this is what I have
    Code:

    download = $this->fields->getFieldById(29);
    echo $download->getOutput(1);

    by the way I do not have access to private forum

    _______________________________________________

    [url=https://www.expressapartments.com] Hotel Italy [/url] | [url=https://www.expressapartments.com] Apartments Italy [/url]

    Thank you starscr3am. I fought this one for a few hours until I found this post.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How do I hide an empty custom field?’ is closed to new replies.