【发布时间】:2014-02-16 00:30:58
【问题描述】:
我找到了这样的东西: Is it possible to create a shortcode that will query a post based on taxonomies
function posts_shortcode_handler($atts, $content) {
extract(shortcode_atts(array(
'posts_per_page' => '5',
'post_type' => 'gallery'
), $atts));
global $post;
$temp = $post;
$posts = new WP_Query($atts);
$retVal = '';
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
// these arguments will be available from inside $content
$parameters = array(
'PERMALINK' => get_permalink(),
'TITLE' => get_the_title(),
'CONTENT' => get_the_content(),
'CATEGORIES' => get_the_category_list(', '),
'THUMBNAIL' => get_the_post_thumbnail()
);
$finds = $replaces = array();
foreach ($parameters as $find => $replace) {
$finds[] = '{' . $find . '}';
$replaces[] = $replace;
}
$retVal .= str_replace($finds, $replaces, $content);
}
}
wp_reset_query();
$post = $temp;
return $retVal;
}
add_shortcode('galerie', 'posts_shortcode_handler');
我的简码如下所示:
[galerie post_type="gallery" posts_per_page="5" taxonomy_name="movies"]
<h5><a href="{PERMALINK}">{TITLE}</a></h5>
<div>{THUMBNAIL}
{CONTENT}</div>
[/galerie]
我的问题是关于不适合我的 taxonomy_name="movies"。 在我的自定义分类名称“类别”中,我有两个子类别“电影”和“照片”。 简码忽略选择的 'taxonomy_name' 并显示来自 post_type="gallery" 的所有自定义帖子。我想在我的 custom_taxonomy 中选择子类别来显示短代码中的自定义帖子类型。
请帮帮我,我卡住了:(
【问题讨论】: