我在网上看到侧边栏读者墙的实现方法 今天和大家分享一下!
把代码放到sidebar.php 中
具体代码:
- <!– 读者墙 –>
- <div>
- <h2>吐槽大神</h2>
- <ul>
- <?php
- $counts = $wpdb->get_results(“SELECT COUNT(comment_author) 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 MONTH ) AND user_id=’0′ AND comment_author != ‘疯孩子’ AND post_password=” AND comment_approved=’1′ AND comment_type=”) AS tempcmt GROUP BY comment_author ORDER BY cnt DESC LIMIT 18″);
- foreach ($counts as $count) {
- $c_url = $count->comment_author_url;
- if ($c_url == ”) $c_url = ‘http://www.fenghaizi.com/’;
- $mostactive .= ‘<li>’ . ‘<a href=”‘. $c_url . ‘” title=”‘ . $count->comment_author . ‘ (‘. $count->cnt . ‘次吐槽)”>’ . get_avatar($count->comment_author_email, 40) . ‘</a></li>’;
- }
- echo $mostactive;
- ?>
- </ul>
- </div>
- <!– 读者墙结束 –>
复制代码
DESC LIMIT 18 (把18换成你想要显示的数量)
comment_author != ‘疯孩子’ (把疯孩子替换成你的用户名)
$c_url = ‘http://www.fenghaizi.com/’; (换成你的网址)
参考CSS样式
- #sidebar .ffox_most_active{overflow:hidden;}
- #sidebar ul.ffox_most_active li{padding-left:0;}
- #sidebar .ffox_most_active li{list-style:none;float:left;line-height:0;border:none;background:none;}
- #sidebar .ffox_most_active img.avatar{width:36px;height:36px;border:1px solid #ddd;padding:2px;margin:0 1px 0 0;}
|
对于我新人,看得有点困难
我按照这个教程搞的,基本上没问题。