我正在編寫一個腳本來顯示10個最近「活躍」的WordPress博客文章(即那些有最新評論的文章)。問題是,該列表有很多重複。我想清除重複項。有沒有一種簡單的方法來通過改變MySQL查詢(如IGNORE,WHERE)或其他方式來做到這一點?這是我到目前爲止有:MySQL - 跳過重複的WordPress條目
<?php
function cd_recently_active() {
global $wpdb, $comments, $comment;
$number = 10; //how many recently active posts to display? enter here
if (!$comments = wp_cache_get('recent_comments', 'widget')) {
$comments = $wpdb->get_results("SELECT comment_date, comment_author, comment_author_url, comment_ID, comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
wp_cache_add('recent_comments', $comments, 'widget');
}
?>
我被描述混淆。它是否正確? 您正在尋找最近評論過的10個不同帖子中每個帖子的最新評論的詳細信息。 – Oddthinking 2008-11-30 23:20:48