• Resolved Lindsey

    (@lalindsey)


    I want to use a conditional on my single pages, that will display content from a custom field only if the custom field contains a value.

    How would I go about this?

    This is the bit of code that I have displaying the custom field:

    <div class="page-top"></div>
    <div class="page-preview know"><h3>Did You Know?</h3>
    <p class="know"><?php $values = get_post_custom_values("Know"); echo $values[0]; ?></p>
    </div>
    <div class="page-bottom"></div>

    I know I have to formulate some sort of if statement, but how?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Not sure whether this is what you mean, but try this:

    <?php $values = get_post_custom_values("Know");  ?>
    <?php if ($values[0]){ ?>
    <div class="page-top"></div>
    <div class="page-preview know"><h3>Did You Know?</h3>
    <p class="know"><?php echo $values[0]; ?></p>
    </div>
    <div class="page-bottom"></div>
    <?php } // this ends the IF ?>
    Thread Starter Lindsey

    (@lalindsey)

    Thanks so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using Conditionals for Custom Fields’ is closed to new replies.