前端集合 - 关注前端技术和互联网免费资源

关注前端技术和互联网免费资源

分类儿

页面儿

搜索儿

前端集合 RSS订阅
Home » 经验记录 » 让wordpress最新评论不显示管理员评论的简单方法

让wordpress最新评论不显示管理员评论的简单方法

发布者:前端集合 // 发布时间:2010-04-03 08:53:55 // 分类:经验记录 // 访问: 3,130 次 // 热度:

wordpress默认会在侧边栏的最新评论显示出你自己回复的评论。我觉得这样很不好,占了最新评论那里宝贵的地理位置。

侧边栏的最新评论寸土寸金,怎能让博主自己的评论回复去玷污它呢?所以,必除之。

用插件?不爽。为了体现至高无尚的折腾精神,还是自己改代码吧:

在function.php或sidebar.php里找到如果代码块

<?php
function recent_comment($comment_nums = 20) {global $wpdb;

$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) 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 post_password = ” AND user_id !=1 ORDER BY comment_date_gmt DESC LIMIT $comment_nums”;

$comments = $wpdb->get_results($sql);

$output = $pre_HTML;

foreach ($comments as $comment) {

$output .= “\n<li>”. “<a href=\”” . get_permalink($comment->ID) . “#comment-” . $comment->comment_ID . “\” title=\””.
$comment->post_title . “\”>” . strip_tags($comment->com_excerpt) .”</a></li>”;}

$output .= $post_HTML;

echo $output;

}?>

红色之处就是需要添加的代码。

ok!

Tags: Wordpress, 最新评论, 不显示管理员评论

杯具:Google PR更新,本博由2降为1>>  << 今天不仅仅是愚人节—张国荣
Top