Javascript 如何隐藏<;i>;标记是否为<;a>;标签是空的
如果Javascript 如何隐藏<;i>;标记是否为<;a>;标签是空的,javascript,php,css,wordpress,Javascript,Php,Css,Wordpress,如果 我不知道这是否可以通过CSS或者更可能的javascript来实现,但是任何建议都将不胜感激 在WordPress中,这通常是通过php完成的 尝试将代码替换为: <?php $first_phone_number = do_shortcode('[pods name="wpwc_replace_fields" slug="51" field="phone_number"]');
我不知道这是否可以通过CSS或者更可能的javascript来实现,但是任何建议都将不胜感激 在WordPress中,这通常是通过php完成的 尝试将代码替换为:
<?php
$first_phone_number = do_shortcode('[pods name="wpwc_replace_fields" slug="51" field="phone_number"]');
$second_phone_number = do_shortcode('[pods name="wpwc_replace_fields" slug="142" field="phone_number_2"]');
?>
<p>Get my free no-obligation quote today: <span><i class="fa fa-phone" aria-hidden="true"></i><a href="tel:<?php echo $first_phone_number; ?>"> <?php echo $first_phone_number; ?></a></span><br />
<?php if ($second_phone_number): ?>
<span><i class="fa fa-phone" aria-hidden="true"></i> <a href="tel:<?php echo $second_phone_number; ?>"><?php echo $second_phone_number; ?></a></span>
<?php endif; ?>
</p>
您可以将i
移动到
标记中,然后如果(!您需要使用的任何条件来检查a是否为空){output i}
,否则您什么也不做。感谢@Hillel,这在一定程度上起到了作用,尽管在PODS自定义字段中,我必须有电话号码2的占位符,{{phone2},因此,它可以替换为Google表单中的数据,因此如果填写了这些数据,
标记仍会显示。是否可以进一步深入,比如说当
标记以0开头时,显示
,如果不是,则隐藏它?当然可以,但如果我理解正确,您在后端有一个常量值为“{phone2}”的字段,该字段在前端被从Google表单获取的数据替换?如果是这样,你要么需要前端解决方案,要么需要后端谷歌集成。请澄清是的,是的,在Google sheet字段中输入的任何内容都将替换相关占位符。你的建议是什么?假设你对FE替换几乎没有控制权,我会尝试一种纯CSS方法-有一个空元素的CSS选择器-:empty(请参见此处:)要使其工作,你需要对使用字体的方式做一些小的调整-而不是使用element方法,使用::before方法(请参见此处:)。这样,当Google工作表中没有数据时,您就可以使用:empty选择器隐藏FA图标伪元素。
<?php
$first_phone_number = do_shortcode('[pods name="wpwc_replace_fields" slug="51" field="phone_number"]');
$second_phone_number = do_shortcode('[pods name="wpwc_replace_fields" slug="142" field="phone_number_2"]');
?>
<p>Get my free no-obligation quote today: <span><i class="fa fa-phone" aria-hidden="true"></i><a href="tel:<?php echo $first_phone_number; ?>"> <?php echo $first_phone_number; ?></a></span><br />
<?php if ($second_phone_number): ?>
<span><i class="fa fa-phone" aria-hidden="true"></i> <a href="tel:<?php echo $second_phone_number; ?>"><?php echo $second_phone_number; ?></a></span>
<?php endif; ?>
</p>