-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 没有 Value</br>之后不存在的值。. . 或者基本上如果值为 null 则没有</br>

我猜这将是一个 if 语句,我对这一切都是全新的。. .

4

3 回答 3

1
<?php
$phone2 = c2c_get_custom('phone_2', 'Phone:', '');
if (!empty ($phone2)) {
    echo $phone2 . '<br />';
}
?>

注意:我也更改</br>为,<br />因为您不能那样使用 br 。(嗯,你不应该)

于 2012-05-19T23:01:03.900 回答
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 />')
?>
于 2012-05-20T00:05:52.380 回答
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>*/
于 2012-05-19T22:59:26.570 回答