skip to Main Content

I have to put a condition on this function:

<div class=imagen01>
<?php sacconicase_post_thumbnail();?>
<div class="mostrasconto"><?php echo ("&nbsp"),"-", get_the_author_meta('discount', $post->post_author ),"%" ;?></div></div>

I have to set the following: IF "get_the_author_meta" is empty, dont echo BUT dont show neither the whoole div.mostrasconto. I have to hide this div because there is a background via css

Which is the best solution?

2

Answers


  1. Chosen as BEST ANSWER

    I found a solution with the following

    <div class="imagen01">
    <?php sacconicase_post_thumbnail();
    $discount = trim( get_the_author_meta ('discount', $post->post_author ));
    if ( ! empty( $discount )) {
    echo '<div class="mostrasconto">';
    echo '&nbsp;-', $discount,'%';
    echo '</div>';
    }?>
    

  2. Put an if statement around it.

    <div class=imagen01>
    <?php sacconicase_post_thumbnail();?>
    <?php 
    $discount = get_the_author_meta('discount', $post->post_author );
    if !empty($discount) { ?>
        <div class="mostrasconto"><?php echo ("&nbsp"),"-", $discount,"%" ;?></div>
    <?php } ?>
    </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search