wordpress笔记之侧边栏读者墙
本来用一款插件来显示最活跃读者的,不过文字的看着总是不爽,所以这次就加上了侧边栏读者墙。更何况看着我空空的侧边栏也有点单调,于是就用折腾了这个在侧边栏加上读者墙的效果,同时鼓励评论。
也没有太多技巧,打开你的sidebar.php加入如下代码:
<h2>活跃读者</h2>
<ul class="ffox_most_active">
<?php
$wall= $wpdb->get_results("SELECT COUNT(comment_ID) 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 != 'sailor' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author ORDER BY cnt DESC LIMIT 12");
foreach ($wall as $item)
{ $c_url = $item->comment_author_url;
if ($c_url == '')
$c_url = '#';
$mostactive .= '<li class="mostactive">' . '<a href="'. $c_url . '" title="' . $item->comment_author . ' ('. $item->cnt . 'comments)">' . get_avatar($item->comment_author_email, 40) . '</a></li>';
}
echo $mostactive;
?>
</ul>
参考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;}
ok,搞定!此方法来自:荒野无灯
折腾笔记系列: