Home » WP Trick

WordPress 免插件读者墙 willin 版本

衡天小张,四钻保证

我以前写过关于免插件读者墙的文章,那个版本是按每月评论最多的读者来排序的,也就是每月1号会清零重新计算。文章链接:用代码武装你的wordpress [part 1]

willin 后来根据这个修改了一下,唯一不同的 willin 修改的是按照最近 30 天内评论最多的读者排序的,我觉得这样更适合“最活跃的读者”的定义,所以我今晚换为 willin 这个版本了

因为 willin 的是使用 willin 的简单 gravatar 头像缓存的基础上的代码,我特意改出 2 个版本:1 个是针对没有使用头像缓存的,1 个是使用了头像缓存的。

一、没有使用头像缓存的读者墙代码:

<h2>Most Active Friends</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 != 'zwwooooo' 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://zww.me/'; $mostactive .= '<li class="mostactive">' . '<a href="'. $c_url . '" title="' . $count->comment_author . ' ('. $count->cnt . 'comments)">' . get_avatar($count->comment_author_email, 40) . '</a></li>'; } echo $mostactive; ?> </ul>

说明:

  1. 里面添加了 2 个 class:ffox_most_active 和 mostactive,根据自己模板在 style.css 设置样式吧
  2. 里面的 http://zww.me 改为你自己博客的网址
  3. 代码里面“DESC LIMIT 12”的 12 是要现示的读者数量
  4. 代码里面的“zwwooooo”是指除博主以外的意思,替换为自己的 WP 用户名吧

我的 css 样式参考:

#sidebar .ffox_most_active li{ list-style:none; float:left; border:none; line-height:0; } #sidebar .ffox_most_active img.avatar{ width:38px; height:38px; border:1px solid #ddd;padding:2px;margin:0 1px 0 0;}

二、使用了  willin 的简单 gravatar 头像缓存的读者墙代码:

<h2>Most Active Friends</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 != 'zwwooooo' 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) { $a = get_bloginfo('wpurl') . '/avatar/' . md5(strtolower($count->comment_author_email)) . '.jpg'; $c_url = $count->comment_author_url; if ($c_url == '') $c_url = 'http://zww.me/'; $mostactive .= '<li class="mostactive">' . '<a href="'. $c_url . '" title="' . $count->comment_author . ' ('. $count->cnt . 'comments)"><img src="' . $a . '" alt="' . $count->comment_author . ' ('. $count->cnt . 'comments)" class="avatar" /></a></li>'; } echo $mostactive; ?> </ul>

说明参考第一种

OK,CP吧 ,折腾吧

附 willin 的原文链接:《WordPress 免插件版侧边栏读者墙

声明: 本文采用 BY-NC-SA 协议进行授权 | ZWWoOoOo
转载请注明转自《WordPress 免插件读者墙 willin 版本

Related Posts:

Most Popular

122 Comments.

⊕Leave a comment?
  1. :sad: 按照你的文章 弄了 发现 有点小问题~ Willin的cp过去不行,万戈的也比行,用你说的显示了 可是评论里的头像 除了我的都不显示了~~~郁闷

    #31
  2. :razz: 行了 谢谢 你的好文章

    #32
  3. 谢谢。已经弄好 了。是显示每月的吗?

    #33
  4. :!: 现在都搞 gravatar缓存了...

    #34
  5. 怎么样屏蔽某个人啊?

    #35
  6. 先收藏~ 呵呵

    #36
  7. 没改好。不显图。可能是主体样式差别大。用了一个其他的。呵呵。不过好像修改样式表不起作用。想给图片加个边框

    #37
  8. 不好意思,代码提交不了。

    代码位置

    样式表应该大体怎么改

    #38
  9. @young 这下行了,
    div id="sidebar"
    div id="northsidebar" class="sidebar"
    div class="widget"
    代码
    /div
    /div
    /div
    大体是这样,我不懂css,猜着写成
    #northsidebar .widget.ffox_most_active li
    {
    list-style:none;
    float:left;
    border:none;
    line-height:0;
    }
    #northsidebar .widget.ffox_most_active img.avatar
    {
    width:38px;
    height:38px;
    border:1px solid #ddd;
    padding:2px;
    margin:0 1px 0 0;
    }

    #39
  10. 请教下,为什么我用这个方法,头像垂直现实呢?希望解答下,谢谢! :lol:

    #41
  11. 哈哈,知道了,我忘了加css。

    #42
  12. 这个创意非常好。支持

    #43
  13. 为什么我的在IE下不显示数目呢?

    #44
  14. 我添加好了,可是怎么是竖着显示呢?

    #45
  15. 非常喜欢这个插件

    #46
  16. 我现在就去试试,看自己能折腾出来不。

    #47
  17. 修改不来代码,不知道有没有插件啊?

    #48
  18. 好强大,这么一篇老文居然被我翻出来了,哈哈

    #49
  19. 评论人名下面的浏览器和系统版本怎么实现的呢?是插件吗?

    #50
  20. 我觉得加上
    AND comment_author_url != ''

    这样才更完善,不计算空URL的评论

    #51
  21. 我修改来修改去都不太好看

    #52
  22. 汗,为什么总是找不到在哪儿呀,显示不出这个东东,是哪步没有弄到位啊 :sad:

    #53
  23. 好像没有显示评论的数量哦

    #54

Leave a Reply

B em del U Link Code Quote


Trackbacks and Pingbacks:

Go to comments