这篇日志实在诞生得有些郁闷,按照正常的顺序,本来应该有它的。
昨天我在给朋友建设WP博客的时候,发现没有WP-RecentComments美化方法在我的集思博客存档,无奈,只能到处寻找具体的代码,从而这篇日志诞生了。
修改WP-RecentComments,让侧边栏不显示博主评论。
方法一、
找到并打开WP-RecentComments的core.php文件。
找到里面的代码,大概84行左右吧。
// SQL 查找数据集合
$comments_query = "SELECT comment_author, comment_author_email, comment_author_url,
comment_ID, comment_post_ID, comment_content, comment_type, comment_author_IP,
comment_agent FROM $wpdb->comments, $wpdb->posts WHERE comment_approved = '1' AND comment_post_ID = ID AND post_status = 'publish'" . $sql_protected .
$sql_private . $sql_pingback . $sql_trackback . $sql_administrator . " ORDER BY comment_date_gmt DESC LIMIT " . $start . "," . $size;
在上面的那一坨代码里面找到:
comment_post_ID = ID AND post_status = 'publish'
替换为:
comment_post_ID = ID AND comment_author != '昵称' AND post_status = 'publish'
把昵称换为自己的昵称就OK了。
方法二、
还是在core.php这个文件找到:
$sql_administrator = " AND comment_author_email NOT IN (SELECT A1.user_email FROM $wpdb->users A1, $wpdb->usermeta A2 WHERE A1.ID = A2.user_id AND A2.meta_key = 'wp_capabilities' AND A2.meta_value LIKE '%administrator%')";
把这串代码所属的一段都改成:
// 是否显示管理员用户的 SQL 条件
$sql_administrator = '';
if ($args['administrator'] == 'false') {
$sql_administrator = " AND comment_author_email NOT IN (SELECT A1.user_email FROM $wpdb->users A1, $wpdb->usermeta A2 WHERE A1.ID = A2.user_id AND A2.meta_key LIKE '%capabilities%' AND A2.meta_value LIKE '%administrator%')";
}
方法二的测试在集思博客完美体现。
修改WP-RecentComments让评论作者和内容在一行显示。
两行的评论也太丑了点。
没事,自然有办法WP用的高手这么多,还怕有办不着的事情?
依然在 core.php找到
//core.php line:119 获取信息处
if ($comment->comment_type == 'pingback') {
$result .= '<li class="rc_item rc_pingback">' . sprintf('<div class="rc_info"><span>' . __('Pingback:') . '</span> %1$s</div>', get_comment_author_link()) . '</li>';
} else if ($comment->comment_type == 'trackback') {
$result .= '<li class="rc_item rc_trackback">' . sprintf('<div class="rc_info"><span>' . __('Trackback:') . '</span> %1$s</div>', get_comment_author_link()) . '</li>';
} else if ($args['post'] == 'true') {
$result .= '<li class="rc_item">' . $element_avatar . sprintf('<div class="rc_info"><span class="author_name">%1$s</span> ' . __('on', 'wp-recentcomments') . ' <span class="post_title">%2$s</span></div>', get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '<div class="rc_excerpt">' . $comment_excerpt . '</div></li>';
} else {
$result .= '<li class="rc_item">' . $element_avatar . sprintf('<div class="rc_info"><span class="author_name">%1$s</span>' . rc_get_author_info() . '</div>', '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . $comment->comment_author . '</a>') . '<div>' . $comment_excerpt . '</div></li>';
}
修改为:
if ($comment->comment_type == 'pingback') {
$result .= '<li class="rc_item rc_pingback">' . sprintf(__('Pingback:') . '%1$s', get_comment_author_link()) . '</li>';
} else if ($comment->comment_type == 'trackback') {
$result .= '<li class="rc_item rc_trackback">' . sprintf( __('Trackback:') . '%1$s', get_comment_author_link()) . '</li>';
} else if ($args['post'] == 'true') {
$result .= '<li class="rc_item">' . $element_avatar . sprintf('%1$s' . __('on', 'wp-recentcomments') . '%2$s', get_comment_author_link().':', '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') .$comment_excerpt . '</li>';
} else {
$result .= '<li class="rc_item">' . $element_avatar . sprintf('%1$s' . rc_get_author_info().':', '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . $comment->comment_author . '</a>') . $comment_excerpt .'</li>';
}
这样就可以实现单行的评论栏了。
原创文章转载请注明出处,转载自:[集思博客]:http://www.giisi.com
本文链接:[美化WP-RecentComments]:http://www.giisi.com/design/wp-recentcomments.html
集思博客订阅地址:[http://rss.giisi.com]



有点复杂哦 我试了 不行 可能是我没有改对吧
这是当年的方法了,现在已经3.0+了,可能会不适用了。
这个一直在用,O(∩_∩)O哈哈~
不知道为什么,按照代码修改了,还是没有改过来