我有自己的功能来创建一个短代码。函数将获取类别,并显示post内容。但是,如果我在我的帖子里使用了一些短代码。函数正在工作,但post短代码将显示为类似于短代码[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');我需要提取这篇文章中的邮政编码。有什么建议吗?
发布于 2014-02-02 05:20:03
替代$html.= $post->post_content;
使用此$html.= do_shortcode($post->post_content);
它将提取您的文章,页面内容的短代码。
发布于 2014-01-30 08:13:03
do_shortcode调用该函数并传递要执行的短代码。
示例:
echo do_shortcode('[foo]'); or $var = do_shortcode('[foo]');这是指向短代码文档的链接。
https://stackoverflow.com/questions/21449010
复制相似问题