Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've gone through a few of the other similar topics but any of the solutions won't work for me.

Basically I only want to show an

  • if the custom field has had information added into it.

    Here's my code, even if you don't give me an answer could you point me in the correct direction as to how to do this.

    <div class="height">
    <div class="fourcol">
    <p class="business"><?php the_field('helpline_name'); ?></p>                                                       <div class="category"><p>AREAS OF HELP: <?php the_category(', ') ?></p> </div>
                                                <p><?php the_field('helpline_address'); ?></p>
    </div>
    <div class="fivecol">
    <p class="phone"><?php the_field('helpline_phone_number'); ?></p>
                                                       </div>                       
    <div class="threecol last">
                                                  <ul>
                                                <li><a href="http://<?php echo the_field('helpline_url'); ?>" class="tiptip web" title="<?php echo the_field('helpline_url'); ?>" target="_blank"><?php echo the_field('helpline_url'); ?></a></li>
                                                <li><a href="" class="tiptip comments" title="read comments from others" target="_blank"><?php echo the_field('helpline_comments'); ?></a></li>
                                                <li><a href="mailto:<?php echo the_field('helpline_email'); ?>" class="tiptip email" title="email us your problem"><?php echo the_field('helpline_email'); ?></a></li>
                                            </ul>
    

    Thanks in advance Tyler

    share|improve this question
    add comment

    2 Answers

    up vote 1 down vote accepted

    This is really more of a PHP question than a WordPress question. But, based on this example code:

    <li><a href="http://<?php echo the_field('helpline_url'); ?>" class="tiptip web" title="<?php echo the_field('helpline_url'); ?>" target="_blank"><?php echo the_field('helpline_url'); ?></a></li>
    

    ...it appears that the the_field() function returns a value (since you then echo that returned value. Thus, simply wrap the entire <li> output in a conditional, using the_field():

    <?php
    if ( the_field( 'helpline_url' ) ) {
        ?>
        <li><a href="http://<?php echo the_field('helpline_url'); ?>" class="tiptip web" title="<?php echo the_field('helpline_url'); ?>" target="_blank"><?php echo the_field('helpline_url'); ?></a></li>
        <?php
    }
    ?>
    
    share|improve this answer
        
    Chris that worked like a treat! For any listings now that don't have a website assigned it doesn't show it. Only thing I need to do now is do some playing with the css! –  Tyler May 4 '12 at 13:19
    add comment

    I'd wrap the output in a conditional statement like this.

    <?php if( empty(the_field('helpline_url')) ) : ?>  
    
    <li>
    <a href="http://<?php echo the_field('helpline_url'); ?>" 
    class="tiptip web" title="<?php echo the_field('helpline_url'); ?>" 
    target="_blank">
    <?php echo the_field('helpline_url'); ?>
    </a>
    </li>
    <?php endif; ?>
    

    Which basically translates to:

    1. Check if the_field('helpline_url') is empty.

    2. If it isn't empty, then do comes after : (which is the html that generates the list item)

    There could be typos and spelling errors or whatnot so please triplecheck and make sure I haven't made a mistake, but this is the structure of code you're looking for.

    share|improve this answer
    add comment

    Your Answer

     
    discard

    By posting your answer, you agree to the privacy policy and terms of service.

    Not the answer you're looking for? Browse other questions tagged or ask your own question.