“如果元框空”隐藏它从前端 - WordPress

时间:2015-02-06 10:23:49

标签: javascript wordpress meta-boxes

我在前端显示邮件和手机的值。

如何隐藏或设置为javascript:void(0)

这是我目前的代码:

section id="page-content" class="col-md-8">
                    <h3>About <?php the_title(); ?></h3>
                      <ul class="people-single unstyled inline-block">
                                <li><a href="mailto:<?php echo(types_render_field("person-email", array('raw' => true) )) ; ?>" target="_blank" class="hvr-hang"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span></a></li>
                                <li><a href="tel:<?php echo(types_render_field("person-phone", array('raw' => true) )) ; ?>" target="_blank" class="hvr-hang"><span class="glyphicon glyphicon-earphone" aria-hidden="true"></span></a></li>
                        </ul>
                        <?php the_content(); ?>
                </section>

1 个答案:

答案 0 :(得分:0)

这样的事情应该有效:

<?php 
$personalEmail = types_render_field("person-email", array('raw' => true) ));
$personalPhone = types_render_field("person-phone", array('raw' => true) )); 
?>
<ul class="people-single unstyled inline-block">
    <?php 
    if($personalEmail != "") 
    { ?>
        <li><a href="mailto:" target="_blank" class="hvr-hang"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span></a></li>
    <?php 
    }
    if($personalPhone != "")
    { ?>
        <li><a href="tel:" target="_blank" class="hvr-hang"><span class="glyphicon glyphicon-earphone" aria-hidden="true"></span></a></li>
    } ?>
</ul>

如果电子邮件或电话号码不是空白,则会显示电话号码或电子邮件。