If no input don't display?

时间:2013-09-02 作者:Bogdan Bătrânu

首先,如果我的问题表述不正确,我很抱歉,我是wordpress和php新手。我希望我不是太傻。

我有这个:

<div class="propsmeta clearfix">
        <div class="propslist"><span>Locatie- </span> <span class="propval"> <?php echo get_the_term_list( $post->ID, \'location\', \'\', \' \', \'\' ); ?></span></div>
        <div class="propslist"><span>Tip proprietate- </span> <span class="propval"><?php echo get_the_term_list( $post->ID, \'property\', \'\', \' \', \'\' ); ?></span></div>
        <div class="propslist"><span>Camere - </span> <span class="propval"> <?php echo get_the_term_list( $post->ID, \'bedrooms\', \'\', \' \', \'\' ); ?></span></div>
        <div class="propslist"><span>Băi - </span> <span class="propval"> <?php $bath=get_post_meta($post->ID, \'wtf_bath\', true); echo $bath; ?></span></div>
        <div class="propslist"><span>Garaj - </span> <span class="propval"> <?php $garage=get_post_meta($post->ID, \'wtf_garage\', true); echo $garage; ?></span></div>
        <div class="propslist"><span>Pret- </span> <span class="propval"> <?php $price=get_post_meta($post->ID, \'wtf_price\', true); echo $price; ?></span></div>
        <div class="propslist"><span>Suprafata- </span> <span class="propval"> <?php $suprafata=get_post_meta($post->ID, \'wtf_suprafata\', true); echo $suprafata; ?></span></div>
    </div>
我想如果输入数据为空,我不想在主div中显示

例如,如果锡槽输入数据为空,我希望:

<div class="propslist"><span>Băi - </span> <span class="propval"> <?php $bath=get_post_meta($post->ID, \'wtf_bath\', true); echo $bath; ?></span></div>
不再出现

2 个回复
最合适的回答,由SO网友:Prince Singh 整理而成

<?php $bath=get_post_meta($post->ID, \'wtf_bath\', true); 
if(!empty($bath) ) { ?>

<div class="propslist"><span>Băi - </span> <span class="propval"> <?php  echo $bath; ?></span></div>

<?php } ?>
对每个div!执行类似的操作!。。仅当要在div中显示的数据不为空时才显示div!

SO网友:Unix

Try this:

<?php $bath=get_post_meta($post->ID, \'wtf_bath\', true);
  if ($bath) { ?>
 <div class="propslist"><span>Băi - </span> <span class="propval"> <?php echo $bath; ?></span></div>
<?php } ?>
结束

相关推荐

Functions.php中的帖子ID错误

我试图在我的函数中执行以下代码。php更改我的wordpress博客的标题。function filter_pagetitle($url) { global $wp_query; $the_post_id = $wp_query->post->ID; $the_post_data = get_post($the_post_id); return $the_post_da