doutuo8800 2013-10-21 20:28
浏览 48
已采纳

如何将php变量回显到wordpress短代码中的html链接

In my short code I am dynamically grabbing some custom posts and displaying them. These custom posts have a custom field labeled 'url'. What I'm trying to do is grab the value from that custom field and put it in the href of an anchor tag. The problem is that I can't seem to use echo in a shortcode. It seems that the function do_shortcode might be the answer, but I am not sure how to use it in my case. The problem is in this line:

$retour .= "<a href='".echo $meta_values;."'>";

Here is the rest of the code for the shortcode

function sc_liste($atts, $content = null) {
    extract(shortcode_atts(array(
            "cat" => ''
    ), $atts));
    global $post;

    $myposts = get_posts('post_type=section_modules&category_name='.$cat.'&order=ASC');
    $retour = "<div class='container-fluid sectionBoxContainer'><div class='row-fluid'>";
    foreach($myposts as $post) :
    $meta_values = get_post_meta( $post->ID, 'url', true );
         $retour .= "<a href='".echo do_shortcode();."'>";
         $retour.="<div class='sectionBox span4'><h2>".$post->post_title."</h2><div class='hrule_black'></div><p>".$post->post_content."</p></div>";
         $retour .="</a>";
    endforeach;
    $retour .= "</div></div>";

    return $retour;


}
  • 写回答

3条回答 默认 最新

  • doushuo1989 2013-10-21 20:30
    关注

    You don't echo into a variable, you just concatenate it:

    $retour .= "<a href='".$meta_values."'>";
    echo $retour;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?