1
請幫我在下面討論的方面的工作:WordPress的簡碼不用於查詢不同類別
我已經註冊了這個短代碼: [category_post title="world news" category="world news" link="#"]
調用不同的類別。但問題是,當我發佈並選擇一個類別時,該帖子顯示在所有類別中。但是,我不想要這個。我希望帖子僅在短代碼中提及的類別中顯示。任何人都可以幫我解決這個問題嗎? 請看看在picture,也是我在這裏給U中的功能:
/* 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')
非常感謝你亞當。問題解決了 – 2014-09-05 10:28:54
沒問題,歡迎來Stack! – 2014-09-05 10:29:46