php - if condition when a div has content do this else do that -
i have here script
<div> <?php echo '<strong>other information</strong><br />'; $myname = get_post_meta($post->id, 'acidity_gl', true); if ( $myname ) { echo 'acidity: ' . $myname . '<br />'; } $myname = get_post_meta($post->id, 'wineph', true); if ( $myname ) { echo 'wine ph: ' . $myname . '<br />'; } $myname = get_post_meta($post->id, 'residual_sugar_gl', true); if ( $myname ) { echo 'residual sugar gl: ' . $myname . '<br />'; } ?> </div>
i add condition when if $myname has value display div when there no value on 3 $myname dont display div
try this,
<?php $myname=array(); $name = get_post_meta($post->id, 'acidity_gl', true); if ( !empty($name) ) { $myname[] = 'acidity: ' . $name ; } $name = get_post_meta($post->id, 'wineph', true); if ( !empty($name) ) { $myname[] = 'wine ph: ' . $name ; } $name = get_post_meta($post->id, 'residual_sugar_gl', true); if ( !empty($name) ) { $myname[] = 'residual sugar gl: ' . $name; } if(!empty($myname)) { echo '<div>'; echo '<strong>other information</strong><br />'; echo implode('<br />',$myname); echo '</div>'; } ?>
Comments
Post a Comment