如何在 建立一个读者墙页面,除了可以通过 插件制作外,下面给大家分享大神制作好的 css3读者墙页面:
一、先在主题page文件夹下新建一个php文件,把下面的代码复制上去保存。
年度评论排行 top18';
global $wpdb;
$query1="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 between date_sub(now(),interval 1 year) and now() and user_id='0' and post_password='' and comment_approved='1' and comment_type='') as tempcmt group by comment_author_email order by cnt desc limit 18";
$wall = $wpdb->get_results($query1);
if(empty($wall)) {echo '暂无年度评论数据!
';}
$maxnum = $wall[0]->cnt;
foreach ($wall as $comment)
{
$width = round(40 / ($maxnum / $comment->cnt),2);
//此处是对应的血条的宽度
if( $comment->comment_author_url )
$url = $comment->comment_author_url;
else $url="#";
$avatar = get_avatar( $comment->comment_author_email, $size = '32');
$tmp = "";
$output1 .= $tmp;
}
$output1 = "".$output1."
";
$readers.=$output1;
$readers.='
';
$readers.='本月评论排行 top9
';
global $wpdb;
$query2="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 date_format(comment_date,'%y-%m')=date_format(now(),'%y-%m') and user_id='0' and post_password='' and comment_approved='1' and comment_type='') as tempcmt group by comment_author_email order by cnt desc limit 9";
$wall = $wpdb->get_results($query2);
if(empty($wall)) {echo '暂无本月评论数据!
';}
$maxnum = $wall[0]->cnt;
foreach ($wall as $comment)
{
$width = round(40 / ($maxnum / $comment->cnt),2);
//此处是对应的血条的宽度
if( $comment->comment_author_url )
$url = $comment->comment_author_url;
else $url="#";
$avatar = get_avatar( $comment->comment_author_email, $size = '32');
$tmp = "";
$output2.= $tmp;
}
$output2 = "".$output2."
";
$readers.=$output2;
$readers.='
';
$readers.='本周评论排行 top9
';
global $wpdb;
$query3="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 yearweek(date_format(comment_date,'%y-%m-%d')) = yearweek(now()) and user_id='0' and post_password='' and comment_approved='1' and comment_type='') as tempcmt group by comment_author_email order by cnt desc limit 9";
$wall = $wpdb->get_results($query3);
if(empty($wall)) {echo '暂无本周评论数据!
';}
$maxnum = $wall[0]->cnt;
foreach ($wall as $comment)
{
$width = round(40 / ($maxnum / $comment->cnt),2);
//此处是对应的血条的宽度
if( $comment->comment_author_url )
$url = $comment->comment_author_url;
else $url="#";
$avatar = get_avatar( $comment->comment_author_email, $size = '32');
$tmp = "";
$output3 .= $tmp;
}
$output3 = "".$output3."
";
$readers.=$output3;
echo $readers;
?>
二、在后台新建一个页面,模板选:读者墙即可!
如下是最终的效果图:
# 更多技巧,请关注「专题」