2012-05-19 70 views
-1
<?php echo c2c_get_custom('contactname', '<strong>Contact: ', '</strong>'); ?></br> 
    <?php echo c2c_get_custom('address', '', '</br>'); ?></br> 
    <?php echo c2c_get_custom('mailingaddress', '', ''); ?></br> 
    <?php echo c2c_get_custom('Town', '', ', MB'); ?></br> 
    <?php echo c2c_get_custom('phone_1', 'Phone:', ''); ?></br> 
    <?php echo c2c_get_custom('phone_2', 'Phone:', ''); ?></br> 
    <?php echo c2c_get_custom('phone_tollfree', 'Toll Free:', ''); ?></br> 
    <?php echo c2c_get_custom('email', 'Email:', ''); ?></br> 
    <?php echo c2c_get_custom('website', 'Website:', ''); ?></br> 

我怎麼把它這樣,如果沒有爲phone_2值沒有價值的</br>是後不存在。 。 。或基本上如果價值爲零沒有</br>如果返回值,則包括</br>如果沒有返回值則沒有</br>

我猜這將是一個if語句,我只是品牌新的所有這一切。 。 。

+0

忘了寫正確的代碼應該說'
' –

+0

如果你犯了一個錯誤,你可以點擊編輯按鈕來編輯你的文章。 –

+6

'
'在任何HTML規範中都是無效的。 – Eric

回答

1

函數的定義是這樣的:

function c2c_get_custom( 
    $field, 
    $before='', 
    $after='', 
    $none='', 
    $between='', 
    $before_last='' 
) 

從這裏獲得:通過http://wordpress.org/extend/plugins/get-custom-field-values/other_notes/

因此各行應類似於此:

c2c_get_custom('phone_2', 'Phone:', '<br />', ''); 

如果上述不起作用,那麼以下幾點就足夠了:

<?php 
    $phone2 = c2c_get_custom('phone_2', 'Phone:', ''); 
    echo (is_null($phone2) || $phone2 == '' ? '' : $phone2.'<br />') 
?> 
+0

這兩個工作,謝謝! –

+0

偉大的,使用第一個,因爲這是該功能打算使用的方式。 – Martin

0
$phone2 = c2c_get_custom('phone_2', 'Phone:', ''); 

/*You can use an if statement like: */ 
if(is_null($phone2) || !isset($phone2)) 
{ 
    print "no" . "<>"; 
} 
else 
{ 
    print $phone2; 
} 

/* or you can also do: */ 

print (is_null($phone2) || !isset($phone2)) ? "no" : $phone2; 

/*You can add in your </br> anywhere needed here. 
Also if your trying to put a line break there, its <br /> and not </br>*/ 
1
<?php 
$phone2 = c2c_get_custom('phone_2', 'Phone:', ''); 
if (!empty ($phone2)) { 
    echo $phone2 . '<br />'; 
} 
?> 

注:我也改變</br><br />,因爲你不能使用BR這樣。 (當然,你不應該)

+0

爲什麼這會降低投票率?這似乎是OP正在尋找什麼,或者我錯過了什麼? – Jeroen

+0

謝謝你們,這是完美的! –

相關問題