<?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>
之后就不存在了......或者基本上如果值为 null 则没有</br>
猜这将是一个if声明,我只是对这一切的新手。
函数的定义是这样的:
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 />')
?>
<?php
$phone2 = c2c_get_custom('phone_2', 'Phone:', '');
if (!empty ($phone2)) {
echo $phone2 . '<br />';
}
?>
注意:我还</br>
更改为<br />
,因为你不能那样使用 br。(好吧,你不应该(
$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>*/