首页 » 建站资料 » 网页设计 » 浏览内容 (希望大家帮忙点击一下图片上的广告)
WordPress Tstyle主题不显示管理员最新评论、留言
相信有很多童鞋和我一样喜欢Tstyle这款WordPress 主题,嗯在这里我不得不说作者T很NB,做出来这么好的主题,但是这款主题默认情况下最新留言和评论是显示管理员的回复的,所以这多多少少有点遗憾,还好修改这个不是很麻烦,所以,我把我自己修改的一些新的告诉给大家,希望能帮助一下你们,其他主题和这个方法也差不多,自己对照尝试就可以了。
由于默认情况下,管理员的ID一般都是为1,所以我们只要排除ID为1的用户的留言和评论就可以了,在WordPress中user_id !=1就是排除管理员信息的留言与评论的,因此我们只要在SQL语句中排除管理员的就好了。
好了,废话也不多说了,直接上代码,修改此主题目录下面的functions.php文件里面的代码,默认情况下因该在27行,这个结构段代码如下:
|
//最新评论、留言
function recent_comment( $comment_post_ID=0, $get_total=5, $show_author_url=1, $before=’<li>’, $after=’</li>’) { global $wpdb; $is_gb =($comment_post_ID == “0″) ? ” != ‘guestbook’ ” : ” = ‘guestbook’ “; $request=”SELECT ID, post_name, comment_ID, comment_content, comment_author_email, comment_author, comment_author_url, comment_date, post_title FROM $wpdb->comments “; $request .= ” LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID “; $request .= ” WHERE post_status IN (‘publish’,'static’) AND comment_approved=’1′ AND $wpdb->posts.post_name “.$is_gb.” AND user_id !=1 ORDER BY comment_ID DESC LIMIT $get_total”; $comments=$wpdb->get_results($request); if ($comments) { foreach ($comments as $comment) { $email=$comment->comment_author_email; $grav_url=”http://www.gravatar.com/avatar/”.md5($email).”?s=32″; $comment_author=stripslashes(strip_tags($comment->comment_author)); $comment_content=utf8Substr(stripslashes(strip_tags($comment->comment_content)),0,150); if ($show_author_url == 1 && strlen($comment->comment_author_url) > 12) $comment_author=’<a target=”_blank” rel=”nofollow” title=”访问 ‘.$comment_author. ‘的网站” href=”‘ . $comment->comment_author_url . ‘”>’ . $comment_author . ‘</a>’; $post_title=stripslashes($comment->post_title); $comment_date=date(“m-d H:i”,strtotime($comment->comment_date)); $permalink=get_permalink($comment->ID).”#comment-”.$comment->comment_ID; $output=$before.”\n”; |
只要把这个替换就好了,其中重点标记的地方就是SQL语句的关键。这个因该还是很简单的,注意修改代码是不要用Windows默认的记事本就行了,至于原因自己百度吧~~



