2016-02-11 42 views
2

我試圖隱藏所有的HTML,如果我的自定義字段中的WordPress隱藏的HTML,如果空的,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 } ?> 

但只有1個定製字段顯示,任何想法爲什麼?我看着它頗有幾分,但不能弄明白

+1

什麼是the_field( 'attribute_1')'和'the_field的'(價值'value_1')'?你應該使用'&&'。 – mkaatman

+0

當我使用&& only屬性_1顯示 –

+0

時,這些值只是常規文本,當前爲asdasd屬性_1和as_2屬性_0 您的意思是使用&& - 這是正確的。你的不正確。 –

回答

0

假設你的領域是正確的(attribute_1value_1),然後用代碼中的問題是使用不正確的功能。

the_field輸出該字段的內容。

在你if情況下,你需要使用get_field回報領域的內容:

<?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 } ?> 
+0

你不知道你讓我感到高興,謝謝你的幫助和解釋。現在我知道供將來參考!謝謝,謝謝!! –

0

因爲您沒有提供有關上面列出的方法的詳細信息,你可以嘗試這樣的事情。

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