[英]How to use shortcode inside shortcode (WordPress)
I have my own function to create a shortcode. 我有自己的功能来创建简码。 Function will get the category, and display the post contents.
函数将获取类别,并显示帖子内容。 But, if I used some shortcode inside my post.
但是,如果我在帖子中使用了一些简码。 Function is working, but post shortcode will show as like shortcode
[gallery]
. 函数正在运行,但后简码将显示为简码
[gallery]
。
/*------------------------------------------*/
/**[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');
I need to extract the post shortcode in this foreach. 我需要在此foreach中提取邮政简码。 Any suggestions?
有什么建议么?
do_shortcode
You call that function and pass the shortcode you want to execute. 您调用该函数并传递要执行的短代码。
Example: 例:
echo do_shortcode('[foo]'); or $var = do_shortcode('[foo]');
Here's the link to the do_shortcode documentation . 这是do_shortcode文档的链接。
Replaced $html.= $post->post_content;
替换
$html.= $post->post_content;
Using this $html.= do_shortcode($post->post_content);
使用此
$html.= do_shortcode($post->post_content);
It will extract your post, page contents shortcodes. 它将提取您的帖子,页面内容的简码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.