为WordPress个性化主题添加读者墙(最活跃的读者)功能
最近在为客户修改WordPress博客主题的过程中,一个要求是在侧边栏增加读者墙功能,就是将站点活跃读者的头像显示在侧边栏,以更好地鼓励朋友多评论,增加站点的互动性。实现读者墙功能的插件倒是不少,不过为了WordPress的简洁,在此采取代码方案实现该需求。
将以下代码粘贴到主题functions.php 文件里面:
function zsofa_most_active_friends($friends_num = 10) {
global $wpdb;
$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 $friends_num");
foreach ($counts as $count) {
$c_url = $count->comment_author_url;
if ($c_url == '') $c_url = get_bloginfo('url');
$mostactive .= '
' . '. $c_url . '" title="' . $count->comment_author .' ('. $count->cnt . 'comments">' . get_avatar($count->comment_author_email, 32) . '
';
}
return $mostactive;
}
但是如何调用以上函数呢?调用方法如下:
Most Active Friends
他们说的对 呵呵 假如是分享代码的话 这样就很不方便了。。
不能选择复制,不科学啊。
话说真的连选中都不可以啊。。。更别说复制了。。。
你这不靠谱啊,文章禁止右键……不能复制
worldpress不太会用