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,搞定!此方法来自:荒野无灯

折腾笔记系列:

 标签: 折腾, 笔记, wordpress, 读者墙

作者  :  sailor

仅仅看明白了还不够,能把别人给讲明白了才算及格。


  1. 恩恩,牛叉,学习了,就是好多符号都是中文的,纠结,改起来还蛮麻烦的[face:han]

    September 26th, 2011 at 08:24 pm 回复
      1. sailor
        sailor

        好吧,忘了加占位符

        October 20th, 2011 at 03:41 am 回复
  2. 阿疯
    2#
    阿疯

    我看你也挺会折腾的

    September 26th, 2011 at 08:49 pm 回复
      1. sailor
        sailor

        嘿嘿,生命不息,折腾不止

        October 20th, 2011 at 03:42 am 回复
  3. 梦飞
    3#
    梦飞

    加上个这功能还是很不错地~~也相当于友链了~嘿嘿

    September 26th, 2011 at 09:57 pm 回复
      1. sailor
        sailor

        也不算是吧,只是一种鼓励,如果怕影响seo,可以加nofollow

        October 20th, 2011 at 03:42 am 回复
  4. MurphyL
    4#
    MurphyL

    嘿嘿~~不错哈~~我也折腾了个~~没放在侧边~~[face:guilian]

    September 26th, 2011 at 10:36 pm 回复
      1. sailor
        sailor

        恩,我也感觉蛮不错,可以鼓励读者啊,嘿嘿

        October 20th, 2011 at 03:43 am 回复
          1. 嘿嘿~又睡了?~~

            October 21st, 2011 at 10:16 pm 回复


最新文章