2013-10-21 20:28
浏览 48


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) {
            "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>";
    $retour .= "</div></div>";

    return $retour;


图片转代码服务由CSDN问答提供 功能建议

在我的短代码中,我动态地抓取一些自定义帖子并显示它们。 这些自定义帖子有一个标有“url”的自定义字段。 我想要做的是从该自定义字段中获取值并将其放在锚标记的href中。 问题是我似乎无法在短代码中使用echo。 似乎函数do_shortcode可能是答案,但我不知道如何在我的情况下使用它。 问题在于这一行:

  $ retour。=“&lt; a href ='”。echo $ meta_values;。“'&gt;”; 


  function sc_liste($ atts,$ content = null){
),$ atts)); 
 global $ post; 
 $ myposts = get_posts('post_type = section_modules&amp; category_name ='。$  cat。'&amp; order = ASC'); 
 $ retour =“&lt; div class ='container-fluid sectionBoxContainer'&gt;&lt; div class ='row-fluid'&gt;”; 
 foreach($ myposts 作为$ post):
 $ meta_values = get_post_meta($ post-&gt; ID,'url',true); 
 $ retour。=“&lt; a href ='”。echo do_shortcode();.''&gt;  ;“; 
 $ retour。=”&lt; div class ='sectionBox span4'&gt;&lt; h2&gt;“。$ post-&gt; post_title。”&lt; / h2&gt;&lt; div class ='hrule_black'&gt;  &lt; / div&gt;&lt; p&gt;“。$ post-&gt; post_content。”&lt; / p&gt;&lt; / div&gt;“; 
 $ retour。=”&lt; / a&gt;“; 
 endforeach; \  n $ retour。=“&lt; / div&gt;&lt; / div&gt;”; 
  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条)

相关推荐 更多相似问题