北极寒流 » 网络资源 » WordPress读者墙免插件版 - 2010.08.13

WordPress读者墙免插件版

既然已经折腾了WordPress这么久,也就不在乎再折腾一把了,上次非插件实现了gravatar 头像缓存功能,今天就再整一次WordPress读者墙免插件版。纯CP党,所以只贴重要部分。

这次的WordPress读者墙有2 个版本:1 个是针对没有使用头像缓存的,1 个是使用了头像缓存的。关于 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) {
$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>

说明参考第一种
文章来源:http://zww.me/archives/24732