解决无法隐藏博主的最新评论

为了调整评论的事情,又折腾起来了,以前那段评论调用代码已经很满意了,但是最近想换个花样,所以再次折腾,平时折腾起来也就加下代码,改下代码,这次还真遇到一个奇怪的事情,希望知道的童鞋留言告之其原理,虽然解决了,但还是疑点多多!在还没解决之前,google了一下,参照ZWWoOoOo的带头像显示的最新评论代码 - 完善篇 不行,好换个看看,继续google,万戈的Wordpress 隐藏博主的最新留言 又不行,好了,不继续了,仔细看下代码,都差不多,只是美观问题,我感觉还是很喜欢zwwooooo现在的侧边最新评论,前面是头像,右上面是内容,右下面是作者,看起来很不错,就是不知道他肯共享具体样式么?呵呵,话撤回来,无非最重要的就是那句:comment_author != '郑 永' ,但是大家仔细观察一下下面的两段个代码,comment_author != 'zhengyong' 和前面说的有何区别?就因为这个问题,刚开始因为不知道,一直以为填zhengyong就可以了,因为上面那段代码是可以的,大家可以想象一下,这一折腾我试了多少个代码,甚至在想是否因为一个页面调用了两次,所以才出现问题的?但就在刚才我去万戈的Wordpress 隐藏博主的最新留言看到他的例子填的是中文名字,于是我就好奇的填中文名字-郑永,结果还是不行,这就怪了,突然马上想到万戈的名字应该不会在后台填写姓万名戈吧?我猜这也不是他真名吧!说到名字,再说说Zwwooooo,我猜他是第4个起zwwo这个名字的人,因为前三个都被抢了,超典型的抢注名字啊!话撤回来,于是我就在我名字中间加个空格,这代码还真牛了,真能识别姓名出来,就这样解决了,大家要是有遇到同类事情,多试试自己的用户名吧。

<h2>踊跃发言排行</h2>
<ul class="ffox_most_active">
<?php
$counts = $wpdb->get_results("SELECT COUNT(comment_author) AS cnt, comment_author, comment_author_url, comment_author_email FROM (SELECT * FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->posts.ID=$wpdb->comments.comment_post_ID) WHERE comment_date > date_sub( NOW(), INTERVAL 1 MONTH ) AND user_id='0' AND comment_author != 'zhengyong' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author ORDER BY cnt DESC LIMIT 12");
foreach ($counts as $count) {
$c_url = $count->comment_author_url;
if ($c_url == '') $c_url = 'http://www.xptt.com/';
$mostactive .= '<zhengyong class="mostactive">' . '<a href="'. $c_url . '" title="' . $count->comment_author . ' ('. $count->cnt  . '评论)">' .get_avatar($count->comment_author_email,40).'</a></zhengyong>';
}
echo $mostactive;
?>
</ul>

以上代码是有效果的。

<div class="widget">
<h3>最新评论</h3>
<ul>
<?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,12) 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;
?>

这个代码也有效果!

分类:网络博客 标签:,,,

上一篇:为什么写博客

下一篇:有没有这样的想法

已经有4条评论!

Loading...
  1. 这个办法用半年多了……把你评论用的名字填进去就行了。或者comment_author_email != 你的邮箱 之类的也行。我用的是邮箱。

    沙发!
  2. 不错..最近正在整理侧边栏..

    板凳!

Leave a Reply to 阿修

gravatar

冷笑 忧伤 恶魔 笑脸 红脸 咧嘴笑 吃惊 惊讶 困惑 耍酷
大笑 抓狂 痛苦 转眼珠 眨眼 好主意 囧 无表情 哭泣 坏笑