• Resolved do77

    (@do77)


    Hi,

    I want to display the content of a custom field on a single page only when the custom field was actually filled out. I know how to pull a custom field’s value into the template and add CSS style to it.

    However, using the if/else statement the value including css style should only show up “if” the custom field was filled out. Right now the value shows up after the div containers but I kind of struggle to make it show up in the right place.

    Its probably pretty basic php stuff but I still can’t make it work!

    So here is my latest attempt:

    <?php
    $skills_values = get_post_meta($post->ID, 'skills', true);
    if ($skills_values){
    echo '<div class="listing-info-left">
    <h2>Required Skills</h2>
    <div class="inner-listing">
    </div>
    </div>' .$skills_values;
    }
    else {
    
    echo ' ';
    }
    ?>

    I would appreciate some help with that!

    Many thanks,
    do77

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    this might work:

    <?php
    $skills_values = get_post_meta($post->ID, 'skills', true);
    if ($skills_values){
    echo '<div class="listing-info-left">
    <h2>Required Skills</h2>
    <div class="inner-listing">'
    .$skills_values
    .'</div>
    </div>';
    }
    else {
    
    echo ' ';
    }
    ?>
    Thread Starter do77

    (@do77)

    Yep, that did work. Thanks so much again!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘If/Else Custom Field (Adding style)’ is closed to new replies.