Forums

[resolved] If/Else Custom Field (Adding style) (3 posts)

  1. do77
    Member
    Posted 1 year ago #

    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

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    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 ' ';
    }
    ?>
  3. do77
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.