【发布时间】:2008-11-20 19:04:30
【问题描述】:
我正在编写一个脚本来显示 10 个最近“活跃”的 WordPress 博客文章(即那些具有最新 cmets 的文章)。问题是,该列表有很多重复项。我想清除重复项。有没有一种简单的方法可以通过更改 MySQL 查询(如 IGNORE、WHERE)或其他方式来做到这一点?到目前为止,这是我所拥有的:
<?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' );
}
?>
【问题讨论】:
-
我对描述感到困惑。这个对吗?您正在查找最近评论的十个不同帖子中每一个的最新评论的详细信息。