dongqiu3709 2013-09-29 15:19
浏览 30
已采纳

Wordpress中的PHP结构

I have this code and works fine:

global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'colors', true);

I want delete characters , and insert <br /> with code like this:

echo str_replace(",", "<br />", get_post_meta($postid, 'colors', true));

But, how can I put both of codes correctly in PHP?

If I put this, it won't work:

global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'colors', true);
echo str_replace(",", "<br />", get_post_meta($postid, 'colors', true));
  • 写回答

1条回答 默认 最新

  • doubeizhong5178 2013-09-29 15:55
    关注

    Try this:

    <?php 
    global $wp_query; 
    $postid = $wp_query->post->ID; 
    echo str_replace(',', '<br />', get_post_meta($postid, 'colors', true));
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?