"如果元框为空“;从前端隐藏它-WordPress

"if meta box empty" hide it from front end - WordPress

本文关键字:前端 隐藏 -WordPress 如果 quot      更新时间:2023-09-26

我在前端显示邮件和电话的值。

如何隐藏或设置为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>

这样的东西应该可以工作:

<?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>

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