首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在短代码中使用短代码(WordPress)

如何在短代码中使用短代码(WordPress)
EN

Stack Overflow用户
提问于 2014-01-30 06:03:37
回答 2查看 742关注 0票数 0

我有自己的功能来创建一个短代码。函数将获取类别,并显示post内容。但是,如果我在我的帖子里使用了一些短代码。函数正在工作,但post短代码将显示为类似于短代码[gallery]

代码语言:javascript
复制
/*------------------------------------------*/
/**[cat] shortcode function - by Yesh**/
/*------------------------------------------*/
function categoryShortcode($atts) {
  //Extract Shotcode from the pages and posts
  extract(shortcode_atts(array('slug' => 'default'), $atts));
  global $post;
  $args = array( 'numberposts' => 5, 'category_name' => $atts['slug'], 'orderby'  => 'post_date', 'order' => 'DESC');
  $posts = get_posts( $args );
  $html="";
  foreach ($posts as $post) {
    $category = get_the_category(); //Get the category from the post
    $cat_img = z_taxonomy_image_url(get_category_by_slug($category[1]->name)->term_id);//Get image url from the child category 
    $html.='<div id="parent-cat-image-'.$category[1]->name.'" style="margin-top:-42px;background-position:right center;height:580px;background-image:url('.$cat_img.');">';
    $html.='<div id="cat-title">';
    $html.='<p id="parent-name">'.get_category_by_slug($category[0]->name)->name.'</p>';
    $html.='<h1 id="cat-name">'.$category[1]->name.'</h1>';
    $html.='<p id="read-more">Read More</p>';
    $html.='</div>';
    $html.='</div>';
    $html.='<div id="pack-post-content-'.$category[1]->name.'" style="min-height:400px;display:none;">';
    $html.='<div id="contents" class="post-cont">';
    $html.= $post->post_content;
    $html.='</div>';
    $html.='</div>';
  }
  return $html;
}
add_shortcode('cat', 'categoryShortcode');

我需要提取这篇文章中的邮政编码。有什么建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-02 05:20:03

替代$html.= $post->post_content;

使用此$html.= do_shortcode($post->post_content);

它将提取您的文章,页面内容的短代码。

票数 0
EN

Stack Overflow用户

发布于 2014-01-30 08:13:03

代码语言:javascript
复制
do_shortcode

调用该函数并传递要执行的短代码。

示例:

代码语言:javascript
复制
echo do_shortcode('[foo]'); or $var = do_shortcode('[foo]');

这是指向短代码文档的链接。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21449010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档