在前面已经介绍了张戈博主的《按年月周排行的读者墙插件》,但是有些博友想纯代码实现,但又不是很懂如何根据现有的读者墙修改成为按年、月、周评论排行的读者墙,今天就将本站使用的读者墙代码分享给大家,希望大家有空的时候折腾一下,从而推进按年、月、周评论排行的读者墙。
具体步骤如下:
1、把以下代码添加到我们的留言板模板文件的<?php the_content(); ?>下面,或get_template_part( 'content', 'page' );下面:
- <h3><?php _e('年度评论排行 TOP6','boke123'); ?></h3>
- <?php
- $author_email = get_option('admin_email');
- $queryy="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')=date_format(now(),'%Y') AND user_id='0' AND comment_author_email != '" . $author_email . "' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author_email ORDER BY cnt DESC LIMIT 6";
- $wally = $wpdb->get_results($queryy);
- $maxNum = $wally[0]->cnt;
- foreach ($wally as $commenty)
- {
- $width = round(40/($maxNum / $commenty->cnt),2);
- if( $commenty->comment_author_url )
- $urly = $commenty->comment_author_url;
- else $urly="#";
- $avatar = get_avatar( $commenty->comment_author_email, $size = '36',$default = get_bloginfo('template_directory') . '/avatar/'.'default.jpg');
- $tmpy = "<li><a target=\"_blank\" href=\"".$commenty->comment_author_url."\">".$avatar."<em>".$commenty->comment_author."</em> <strong>+".$commenty->cnt."</strong></br>".$commenty->comment_author_url."</a></li>";
- $outputy .= $tmpy;
- }
- $outputy = "<ul class=\"readers-list\">".$outputy."</ul>";
- echo $outputy ;
- ?>
- <h3><?php _e('本月评论排行 TOP6','boke123'); ?></h3>
- <?php
- $querym="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 comment_author_email != '" . $author_email . "' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author_email ORDER BY cnt DESC LIMIT 6";
- $wallm = $wpdb->get_results($querym);
- $maxNum = $wallm[0]->cnt;
- foreach ($wallm as $commentm)
- {
- $width = round(40/($maxNum / $commentm->cnt),2);
- if( $commentm->comment_author_url )
- $urlm = $commentm->comment_author_url;
- else $urlm="#";
- $avatar = get_avatar( $commentm->comment_author_email, $size = '36',$default = get_bloginfo('template_directory') . '/avatar/'.'default.jpg');
- $tmpm = "<li><a target=\"_blank\" href=\"".$commentm->comment_author_url."\">".$avatar."<em>".$commentm->comment_author."</em> <strong>+".$commentm->cnt."</strong></br>".$commentm->comment_author_url."</a></li>";
- $outputm .= $tmpm;
- }
- $outputm = "<ul class=\"readers-list\">".$outputm."</ul>";
- echo $outputm ;
- ?>
- <h3><?php _e('本周评论排行 TOP6','boke123'); ?></h3>
- <?php
- $queryw="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 comment_author_email != '" . $author_email . "' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author_email ORDER BY cnt DESC LIMIT 6";
- $wallw = $wpdb->get_results($queryw);
- $maxNum = $wallw[0]->cnt;
- foreach ($wallw as $commentw)
- {
- $width = round(40/($maxNum / $commentw->cnt),2);
- if( $commentw->comment_author_url )
- $urlw = $commentw->comment_author_url;
- else $urlw="#";
- $avatar = get_avatar( $commentw->comment_author_email, $size = '36',$default = get_bloginfo('template_directory') . '/avatar/'.'default.jpg');
- $tmpw = "<li><a target=\"_blank\" href=\"".$commentw->comment_author_url."\">".$avatar."<em>".$commentw->comment_author."</em> <strong>+".$commentw->cnt."</strong></br>".$commentw->comment_author_url."</a></li>";
- $outputw .= $tmpw;
- }
- $outputw = "<ul class=\"readers-list\">".$outputw."</ul>";
- echo $outputw ;
- ?>
其中LIMIT 6即为显示前6个读者;$default = get_bloginfo('template_directory') . '/avatar/'.'default.jpg')是默认头像地址,建议修改。
如果还没有留言板模板,可以复制所使用主题中的page.php文件,改名为page-zxly.php,然后新建一个页面,这个页面的地址改为zxly即可。
2、把以下代码添加到我们的style.css文件中:
- /* 读者墙 */
- .readers-list{font-size:12px;line-height:18px;text-align:left;_zoom:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
- .readers-list li{width:230px;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:rightright;position:absolute;rightright:6px;top:4px;font:bold 14px/16px microsoft yahei}
- .readers-list a:hover{border-color:#BA4C32;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:#BA4C32;font:bold 14px/36px microsoft yahei}
- .readers-list a:hover strong{color:#BA4C32;rightright:180px;top:0;text-align:center;border-right:#ccc 1px solid;height:44px;line-height:40px}
其中width:230px,可根据实际情况修改,是实现一行显示多少个读者。
3、如果使用的主题也是跟本站一样,是知更鸟的HotNews主题的,可以直接下载本站所使用的留言板模板,然后新建一个页面,选择这个留言板模板即可。文件下载地址(提取码:610a):
下载地址
如若转载,请注明出处:https://www.ozabc.com/jianzhan/405489.html