title: Wordpress最新评论显示内容、不显示自己评论
date: 2012-12-19 12:23:53
category: [编程代码]
tags: [Wordpress]
author: 零贰
<p> 更换主题后,打算尽量的少用插件,原来使用了最新评论侧边栏,现在也弃之不用,打算用WP自带的最新评论了。不过使用WP自带的侧边栏,发现有两个问题:</p> <p> 一是会显示的自己的评论,评论留言较多倒还罢了,像我这种浏览少的,显示的基本上就是自己的回复留言了;</p><!--more-->
<p> 二是显示的内容是留言文章的标题,而不是留言的内容,实在非常的不友好;</p> <p> 所以就在网上找了一个免插件显示最新留言的方法,如下:</p> <p> 1、找到wordpresswp-includesdefault-widgets.php</p> <p> 2、修改代码:</p> <div class="dp-highlighter"> <div class="bar"></div> <ol class="dp-c"> <li class="alt"><span><span class="comment">/1、不显示自己的留言:/</span><span> </span></span> <li><span></span><span class="vars">$comments</span><span>=get_comments(</span><span class="keyword">array</span><span>('number'=></span><span class="vars">$limit</span><span>,'status'=>'approve')); </span></span> <li class="alt"><span></span><span class="comment">/更改成下面的代码/</span><span> </span></span> <li><span></span><span class="vars">$comments</span><span>=get_comments(</span><span class="keyword">array</span><span>('number'=></span><span class="vars">$limit</span><span>,'status'=>'approve','user_id'=>0)); </span></span> <li class="alt"><span></span><span class="comment">/2、显示留言内容:/</span><span> </span></span> <li><span>(_x(‘%1</span><span class="vars">$s</span><span> on %2</span><span class="vars">$s</span><span>’, ‘widgets’) 改成 (_x(‘%1</span><span class="vars">$s</span><span> : %2</span><span class="vars">$s</span><span>’, ‘widgets’) </span></span> <li class="alt"><span>get_the_title(</span><span class="vars">$comment</span><span>->comment_post_ID) 改成 </span><span class="func">strip_tags</span><span>( </span><span class="vars">$comment</span><span>->comment_content) </span></span></li></ol></div> <p></p> <p> </p> <p align="center"><font color="#ffffff">http://www.Cool02.com</font></p>