如果PHP为空,则在自定义字段周围隐藏HTML
如果我的自定义字段在Wordpress中为空,我将尝试隐藏所有html 我用这个:如果PHP为空,则在自定义字段周围隐藏HTML,php,html,wordpress,Php,Html,Wordpress,如果我的自定义字段在Wordpress中为空,我将尝试隐藏所有html 我用这个: <?php if (the_field( 'attribute_1' ) & the_field( 'value_1' ) != "") { ?> <li style="line-height:2.25em;border-top:1px solid #dcdcdc;"><p style="font-size:15px;margin-bottom:0;"><?php
<?php if (the_field( 'attribute_1' ) & the_field( 'value_1' ) != "") { ?>
<li style="line-height:2.25em;border-top:1px solid #dcdcdc;"><p style="font-size:15px;margin-bottom:0;"><?php the_field( 'attribute_1' ); ?> <span style="float:right;font-weight:600;font-family:'Varela Round';"><?php the_field( 'value_1' ); ?></span></p></li>
<?php } ?>
但是只有一个自定义字段出现,你知道为什么吗?我已经仔细研究过了,但是没有弄清楚,假设你的字段是正确的(
attribute\u 1
和value\u 1
),那么代码的问题是使用了不正确的函数
输出该字段的内容
在if
条件下,需要使用返回字段内容的:
<?php if (get_field( 'attribute_1' ) && get_field( 'value_1' ) != "") { ?>
<li style="line-height:2.25em;border-top:1px solid #dcdcdc;">
<p style="font-size:15px;margin-bottom:0;"><?php the_field( 'attribute_1' ); ?> <span style="float:right;font-weight:600;font-family:'Varela Round';"><?php the_field( 'value_1' ); ?></span>
</p>
</li>
<?php } ?>
由于您尚未提供上述方法的详细信息,您可以尝试以下方法
<?php
if(isset("myfield") && isset("myfield2")){
echo "<input type=\"text\" id=\"customField1\"></input>";
} //repeat as necessary
?>
如果您认为“myfield”是来自不同页面的变量,则应使用:
<?php //use $_GET if necessary
if(isset($_POST['myfield']) && isset($_POST['myfield2'])){
echo "<input type=\"text\" id=\"customField1\"></input>";
} //repeat as necessary
?>
_字段('attribute_1')和_字段('value_1')的值是什么?您可能应该使用&&
。这些值只是常规文本,在我使用&&only attribute_1显示时,当前属性_1的asdasd和属性_2的asd。您的意思是使用&&
-这是正确的。你的不正确。啊,是的,我确实使用&&。对不起,我累了,我贴错了。使用&,我只看到1个自定义字段。你不知道你让我有多高兴,谢谢你的帮助和解释。现在我知道了,以备将来参考!谢谢,谢谢!!