一直很不喜欢WP自带的最新评论,看了 WP Kit CN 里边带的最新评论也让我不是很满意。自己还找过几款其他的 Recnet Comment 类似的插件,都是不尽如意。这个修改方法还是在万戈那里看到的。最近从他那抄袭了不少好东西。大家没事去翻翻他博客吧。对折腾 WordPress 肯定有很大的帮助。

其实自己的要求很简单:
1. 不要太花哨
2. 要有 Gravatar 头像
3. 评论者名字
4. 点击留言直接进入相关文章页面

在万戈博客看到很简单的一段代码,连插件都省了,对 WordPress 提速有那么一点效果,不多说啦,看代码吧。

1
2
3
4
5
6
7
8
9
10
11
12
<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,25) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND comment_author != '万戈' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {
$output .= "\n<li>".get_avatar(get_comment_author_email('comment_author_email'), 18). " <a href="" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "" title="" . $comment->post_title . " 上的评论">". strip_tags($comment->comment_author) .": ". strip_tags($comment->com_excerpt) ."</a></li>";
}
$output .= $post_HTML;
$output = convert_smilies($output);
echo $output;
?>

另外升级3.0.1后的朋友可能会造成头像无法显示的问题,请移步:
WordPress 升级 3.0.1 后修改记录

另外补充说明一下:代码中的“万戈”换成各自的名字就行,只是为了隐藏博主的最新留言,还有 gravatar 头像缓存的路径就根据各自的实际情况啦。