以下代码:<?php if (get_post_meta($post->ID,'Phone-price',ture)) { ?> <big><?php the_price($post->ID); ?></big><?php _e('daluhang', 'kubrick'); ?> <?php }?>//首先判断是否存在 Phone-price 的文章标签 ,如果哦存在 则显示 大陆行 

<?php if (get_post_meta($post->ID,'Phone-price1',ture)) { ?> <big><?php the_price1($post->ID); ?></big><?php _e('ganghang', 'kubrick'); ?> <?php }?>//判断是否存在 Phone-price1 的文章标签 ,如果哦存在 则显示 港行 

<?php if (get_post_meta($post->ID,'Phone-price2',ture)) { ?> <big><?php the_price2($post->ID); ?></big><?php _e('gangshui', 'kubrick'); ?> <?php }?> //判断是否存在 Phone-price2 的文章标签 ,如果哦存在 则显示 港水
********************************
这是我自己写的函数 function the_price($post_ID) {
    echo (get_post_meta($post_ID, 'Phone-price', true));
}function the_price2($post_ID) {
    echo (get_post_meta($post_ID, 'Phone-price2', true));
}function the_price1($post_ID) {
    echo (get_post_meta($post_ID, 'Phone-price1', true));
}
总是笨笨的,写不出多么优化的代码。以上代码在运行的时候是不是会拖累网页显示速度。还请各位大哥 们给出出主意 优化下哦 。感谢。

解决方案 »

  1.   


    <?php 
    if (get_post_meta($post->ID,'Phone-price',ture)) { ?> 
    <big><?php the_price($post->ID); ?></big><?php _e('daluhang', 'kubrick'); ?> 
    <?php }?>function the_price($post_ID) {
      echo (get_post_meta($post_ID, 'Phone-price', true));
    }
    echo get_post_meta($post->ID,'Phone-price',ture);
    输出什么内容呢?
      

  2.   


    //如此好看,但是理论上的速度稍微比楼主写的慢点(这种形式)<?php if (get_post_meta($post->ID,'Phone-price',ture)) {echo '<big>';the_price($post->ID); echo '</big>';_e('daluhang', 'kubrick'); }?>
      

  3.   

    没看明白想干什么一般不会,输出小的时候,可以连成字符串一起输出,差别不是那么明显。如果比较大,可以<?php if(){ ?>html <?php } ?>
      

  4.   

    原则,不要重复执行方法一:
     
     $a = get_post_meta($post_ID, 'Phone-price'));
     $b = get_post_meta($post->ID,'Phone-price1'))
     $c = get_post_meta($post->ID,'Phone-price2'));
     $output=''; $output .= $a?"true": _e('daluhang', 'kubrick');
     $output .= $b?"ture": _e('ganghang', 'kubrick');
     $output .= $c?"ture": _e('gangshui', 'kubrick');echo $output;
    --------------------------
    注意函数的返回值,一般在里面不直接echo;get_post_meta看能否再优化
    也可用case 处理