标题其实有些夸张,实际上是对于本博留言板的读者墙重点介绍.
看着别人博客都有个读者墙,眼红,就也弄了个,有想过也塞侧边栏,不过冲着留言板有些空缺,再是参考万戈的留言板里边是文章订阅的,不过我暂时不想整那玩意,于是将读者墙放留言板了.
至于它为什么叫活友情链接,因为它每个月归每个月的,代码自己判断了,所以称之为活恰到好处.
上张图给大伙过过瘾.
先声明我是从万戈博客《WordPress 免插件读者墙修订版》偷过来的.但我研究了一小部分时间后,有些改进,当然了,我还是使用WP固有的get_avatar函数,原生嘛,实际是考虑到它风格的问题.
万戈的代码我就不发了,直接贴上我自己正在用的,因为有些小改动.
主题目录下functions.php部分
/* 读者墙 */
$identity="comment_author";
$passwordpost = " AND post_password=''";
$userexclude = " AND user_id='0' and comment_author != '成'";
$approved = " AND comment_approved='1'";
$shownumber = 42;
$counts = $wpdb->get_results("SELECT COUNT(" . $identity . ") 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 MONTH(comment_date)=MONTH(now()) and YEAR(comment_date)=YEAR(now())" .
$userexclude . $passwordpost . $approved . ") AS tempcmt GROUP BY " . $identity . " ORDER BY cnt DESC LIMIT " . $shownumber);
$identity="comment_author";
$passwordpost = " AND post_password=''";
$userexclude = " AND user_id='0' and comment_author != '成'";
$approved = " AND comment_approved='1'";
$shownumber = 42;
$counts = $wpdb->get_results("SELECT COUNT(" . $identity . ") 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 MONTH(comment_date)=MONTH(now()) and YEAR(comment_date)=YEAR(now())" .
$userexclude . $passwordpost . $approved . ") AS tempcmt GROUP BY " . $identity . " ORDER BY cnt DESC LIMIT " . $shownumber);
留言板部分(记得要加div):
<h3>本月【<?php echo date('Y年m月');?>】评论/留言排行榜</h3>
<ul class="ffox_most_active">
<?php if ( $counts ) :
foreach ($counts as $count) :
$mc+=1;
echo '<li>' . '<a href="'. $count->comment_author_url . '" target="_blank" title="第' .$mc.'名是: '. $count->comment_author . ' ('. $count->cnt . '条评论/留言)">'.get_avatar($count->comment_author_email,32,'','第'.$mc.'名是: '.$count->comment_author . ' ('. $count->cnt . '条评论/留言)').'</a></li>';
endforeach; endif;
?>
</ul>
<ul class="ffox_most_active">
<?php if ( $counts ) :
foreach ($counts as $count) :
$mc+=1;
echo '<li>' . '<a href="'. $count->comment_author_url . '" target="_blank" title="第' .$mc.'名是: '. $count->comment_author . ' ('. $count->cnt . '条评论/留言)">'.get_avatar($count->comment_author_email,32,'','第'.$mc.'名是: '.$count->comment_author . ' ('. $count->cnt . '条评论/留言)').'</a></li>';
endforeach; endif;
?>
</ul>
style.css部分:
/* 读者墙 */
.ffox_most_active li {
list-style:none;
float:left;
border:none;
padding-left:0;
width:41px;
background:none;
}
.ffox_most_active img {
width:32px;
height:32px;
}
.ffox_most_active li {
list-style:none;
float:left;
border:none;
padding-left:0;
width:41px;
background:none;
}
.ffox_most_active img {
width:32px;
height:32px;
}
- 转载请注明来源:凤凰不归巢 » 《非插件为WP打造活友情链接》
- 本文链接地址:http://wancheng.li/1355.html

本文有 69 条评论
牛XX啊! , 正直兄教教我吧 , 这么牛的你要干什么啊 , 我都害怕你危害社会! , 嘻嘻 :lks:
:han: 放心,不会
有时间,咱也弄个!!
看到代码就头疼 我一点技术都不懂 哈哈
你太谦虚了
好东西,收藏,过几天也加上拉风下
读者墙变身成友情链接了
我喜欢……
学习了,博主分享的好啊 :cx:
:jy: 我想请问下你们这个鼠标经过链接移动的是不是插件呢?真的很棒,个人很喜欢。请问有的分享吗??
不是.你去万戈的博客 http://wange.im 搜索下. :wx:
为何我一加functions.php下的代码,整个控制台上方就变成了代码呢?
因为我这代码并非可直接复制粘贴之用啊.仔细些 :wx:
不是直接放在后面? , 不懂,请指教。
加我Q,嘿
你的qq问题真要命,算了
没啥别的意思啊 :dx:
这个问题我已经解决了,呵呵,折腾啊 , 你的留言板是新建的页面吗?插入加的div的class是什么?
交换链接吗? :cx:
可以.我弄好啦.
:dx: 谢谢
我也已经链接好
额~~我在后台新增了一个叫“留言”的页面 , 加入了你的代码: , 你的代码 , 但是显示的是乱码…… , functions.php部分和css部分都已经添加 , 怎么回事捏,能否指教下 :cx:
:dx: :dx: 谢谢分享,支持一下。
喜欢就好.嘿