请帮助我解决下面讨论的问题:
我已注册此短代码:
[category_post title="world news" category="world news" link="#"]
打电话给不同的类别。但问题是当我发布并选择一个类别时,帖子会显示在所有类别中。但是,我不想要这个。我希望帖子只显示在短代码中提到的那个类别中。任何人都可以帮我解决这个问题吗?
请看一下picture,我也给了你这里的功能:
/* Register shortcode for querying custom category post *********/
function category_post_shortcode($atts){
extract( shortcode_atts( array(
'title' => '',
'link' => '',
'category' => '',
), $atts, 'category_post' ) );
$q = new WP_Query(
array( 'category' => $category, 'posts_per_page' => '4', 'post_type' => 'post')
);
$list = '<div class="latest_from_category"><h2 class="latest_frm_cat_title">'.$title.'</h2> <a href="'.$link.'" class="latest_more_link">more</a>';
while($q->have_posts()) : $q->the_post();
//get the ID of your post in the loop
$id = get_the_ID();
$post_excerpt = get_post_meta($id, 'post_excerpt', true);
$post_thumbnail= get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
$list .= '
<div class="single_cate_post floatleft">
<a href="'.get_permalink().'">'.$post_thumbnail.'</a>
<a href="'.get_permalink().'"><h3>'.get_the_title().'</h3></a>
<p>'.$post_excerpt.'</p>
<a href="'.get_permalink().'" class="readmore">বিস্তারিত</a>
</div>
';
endwhile;
$list.= '</div>';
wp_reset_query();
return $list;
}
add_shortcode('category_post', 'category_post_shortcode')
答案 0 :(得分:0)
category
的{{1}}参数需要类别ID - 按名称查询,使用WP_Query
:
category_name
http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters