我在前段時間完成了這項工作。 我的博客上你的解決方案,我知道它在波蘭的但代碼代碼:) http://blog.grabek-adam.pl/2010/06/wordpress-popularne-posty-plugin-do-obrazkw/
在這裏,你剛纔的查詢:
$posty = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS wp_posts.id, wp_posts.post_title, wp_posts.comment_count, wp_posts.post_date
FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'category'
AND wp_term_taxonomy.term_id IN ('cat_id1,cat_id2,cat_id5')
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
AND wp_posts.comment_count > 0
GROUP BY wp_posts.ID ORDER BY wp_posts.comment_count DESC
LIMIT 5
");
該代碼將只包括您在這裏AND wp_term_taxonomy.term_id IN ("cat_id1,cat_id2,cat_id5")
指定類別,但我認爲這將是很容易改變你的要求