关于PHP声明

时间:2013-02-09 14:26:04

标签: php if-statement

任何人都可以帮助我为此声明制作代码

<?php if(get_post_meta($post->ID, "price", $single = true) != ""){ ?>
<?php echo get_post_meta($post->ID, "price",$single = true); ?>
<?php } ?>

如果在我的自定义字段中为空,我希望语句继续使用此代码

<?php $asin = get_post_meta($post->ID, 'asin', true);
echo azon_us_price($asin);
 ?>

1 个答案:

答案 0 :(得分:0)

我想你想这样做:

<?php
if(!empty(get_post_meta($post->ID, "price", $single = true))){ 
  echo get_post_meta($post->ID, "price",$single = true); 
} else {
  $asin = get_post_meta($post->ID, 'asin', true);
  echo azon_us_price($asin);
}
?>