建站服务器
这篇文章将为大家详细讲解有关wordpress实现读者墙的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
wordpress如何实现读者墙?
1.复制page.php页面,改名为readerwall.php,然后在其顶部添加如下代码:
代码如下:
<?php /* template name: reader wall */ ?>提示:你可以先修改部分代码再运行。
2.在需要添加读者墙的位置添加以下代码:
代码如下:
<!-- start 读者墙 edited by isayme--> <?php $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 24 month ) and user_id='0' and comment_author_email != '改成你的邮箱账号' and post_password='' and comment_approved='1' and comment_type='') as tempcmt group by comment_author_email order by cnt desc limit 39";//?>大家把管理员的邮箱改成你的,最后的这个39是选取多少个头像,大家可以按照自己的主题进行修改,来适合主题宽度,代码如下:
代码如下:
<?php $wall = $wpdb->get_results($query); $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 = '36', $default = get_bloginfo('wpurl').'/avatar/default.jpg' ); $tmp = "<li><a target="_blank" href="".$comment->comment_author_url."">".$avatar."<em>".$comment->comment_author."</em> <strong> ".$comment->cnt."</strong></br>".$comment->comment_author_url."</a></li>"; $output .= $tmp; } $output = "<ul class="readers-list">".$output."</ul>"; echo $output ; ?> <!-- end 读者墙 -->提示:你可以先修改部分代码再运行。
3.在主题目录中style.css添加以下样式:
代码如下:
.readers-list{line-height:18px;text-align:left;overflow:hidden;_zoom:1} .readers-list li{width:200px;float:left;*margin-right:-1px} .readers-list a,.readers-list a:hover strong{background-color:#f2f2f2;background-image:-webkit-linear-gradient(#f8f8f8,#f2f2f2);background-image:-moz-linear-gradient(#f8f8f8,#f2f2f2);background-image:linear-gradient(#f8f8f8,#f2f2f2)} .readers-list a{position:relative;display:block;height:36px;margin:4px;padding:4px 4px 4px 44px;color:#999;overflow:hidden;border:#ccc 1px solid;border-radius:2px;box-shadow:#eee 0 0 2px} .readers-list img,.readers-list em,.readers-list strong{-webkit-transition:all .2s ease-out;-moz-transition:all .2s ease-out;transition:all .2s ease-out} .readers-list img{width:36px;height:36px;float:left;margin:0 8px 0 -40px;border-radius:2px} .readers-list em{color:#666;font-style:normal;margin-right:10px} .readers-list strong{color:#ddd;width:40px;text-align:right;position:absolute;right:6px;top:4px;font:bold 14px/16px microsoft yahei} .readers-list a:hover{border-color:#bbb;box-shadow:#ccc 0 0 2px;background-color:#fff;background-image:none} .readers-list a:hover img{opacity:.6;margin-left:0} .readers-list a:hover em{color:#ee8b17;font:bold 12px/36px microsoft yahei} .readers-list a:hover strong{color:#ee8b17;right:150px;top:0;text-align:center;border-right:#ccc 1px solid;height:44px;line-height:40px}提示:你可以先修改部分代码再运行.
关于wordpress实现读者墙的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
请问这个备案要把之前的网站打开吗怎么注册国际域名?管理国际域名的机构是什么?升级IOS11.3后,IPhone5s不如IPhone SE.top域名与.com域名有何区别?域名的结构是怎样的?阿里云服务器备案腾讯注册的域名搭建网站商城的重要性和怎么实现引流自己域名注册技巧有哪些?搭建VMware ESXi6.7的方法