WordPress 侧栏读者墙实现方法

WordPress教程 5332

博客吧没有交换首页友情链接,在前阵子为了提高访客评论的积极性,在侧栏添加了“热情读者”一栏显示30天内评论最多的访客的博客链接,作用相当于全站友情链接。可能这对老博客的吸引力可能不大,但对很难交到链接的新博客还是有些作用的,只要评论几句就能多个单向链接,便宜值得。

WordPress 侧栏“热情读者墙”实现教程:

在博客主题的sidebar.php文件中的相应位置添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
		<h3>热情读者</h3>
		<ol>
<?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 != '板凳' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author ORDER BY cnt DESC LIMIT 8");
foreach ($counts as $count) {
$c_url = $count->comment_author_url;
if ($c_url == '') $c_url = 'https://www.boke8.net/';
$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;
?>
</ol>
  • comment_author != ‘板凳’:把“板凳”替换为自己的用户名。(主要是排除自己)
  • cnt DESC LIMIT 8″:“8”为输出的数量
  • if ($c_url == ”) $c_url = ‘https://www.boke8.net/’:把博客吧的地址更改为自己的

提醒:其中涉及的相关CSS样式自己定义,因为每个博客主题使用的样式都有差异。

PS:这不是新鲜的技巧,老早就有了,只是发现博客吧之前没有分享,所以现在来添加上来。

精品推荐: