在线读者墙html代码,用代码实现wordpress”读者墙”(完美修改版)

前文写到《给博客添加一个”读者墙”,插件wp-reader-wall》,文中也提到了该插件的一些缺点。本着WP fans一贯的折腾的精神,严重浪漫又开始研究起用代码实现读者墙。

一直以来都很喜欢Junan的读者墙,和他聊了一下,得知他的读者墙是代码实现的。于是把代码要来了。使用后,发现有一个小小的问题:点击墙上的头像,会在本页内跳转到别人的博客,这样会造成本博客的“跳出”。于是,我修改了一下,修改后,点击头像,在新页面(或标签)打开别人的博客。这样的话,这段代码就比较完美了。

手把手使用说明:

【1】首先把你现在所用的主题的目录下的page.php这个文件复制一份到你的硬盘上。改名为Reader.php (其他名字也可以,但中文不可以)。

【2】用Notepad++、UltraEdit、EditPlus等文本编辑器打开Reader.php,在最前面加上:

/*

Template Name:Wall

*/

?>

/*

Template Name:Wall

*/

?>

【3】找到<?php the_content(); ?>,在他的前面加上:

$query="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 YEAR) AND user_id='0' AND comment_author_email != 'XXXX@163.com' AND comment_author_email != 'XXXX@gmail.com' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author_email ORDER BY cnt DESC LIMIT 180";

$wall = $wpdb->get_results($query);

foreach ($wall as $comment)

{

if( $comment->comment_author_url )

$url = $comment->comment_author_url;

else $url="#";

$tmp = "".get_avatar($comment->comment_author_email, 40)."";

$output .= $tmp;

}

$output = "

Readers Wall

".$output."
";

echo $output ;

?>

$query="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 YEAR) AND user_id='0' AND comment_author_email != 'XXXX@163.com' AND comment_author_email != 'XXXX@gmail.com' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author_email ORDER BY cnt DESC LIMIT 180";

$wall = $wpdb->get_results($query);

foreach ($wall as $comment)

{

if( $comment->comment_author_url )

$url = $comment->comment_author_url;

else $url="#";

$tmp = "".get_avatar($comment->comment_author_email, 40)."";

$output .= $tmp;

}

$output = "

Readers Wall

".$output."
";

echo $output ;

?>

里面几个数值,你可以根据自己需要修改:

[1 YEAR]   是统计的时间跨度。1 MONTH 是一个月,1 WEEK 是一周,1 SEASON是一季度。

[XXXX@163.com]   是排除掉博主自己的评论。

[180]   是显示多少个头像。

[40]    是头像尺寸。

修改完后,保存。

【4】把Reader.php上传到你现在用的主题的目录下。

【5】wordpress后台 → 页面 → 添加新页面。

标题随便起一个名字,可以是中文。建议起一个英文的别名,比如“ReadersWall”。

右边的“模版”,点开下拉菜单,选择“Wall” (就是刚刚上传的那个模版啦)。

发布页面。

【6】完成了。

从你的首页里找到这个新建的页面,点开看看吧。比如:严重浪漫的读者墙。

写的够详细了,方便菜鸟学习。

祝大家愉快。

本文欢迎转载,转载请注明原作者、原链接。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值