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条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题