在使用wordpress的侧边栏中很多同学会发现有的wordpress有这样一个功能 ' . '' . get_avatar($count, 58) . ' ';
}
return $mostactive;
} 原主题这个小工具是显示不了最近访客的,百度一下看到歧路亡羊博客里面有介绍实现,但是不能抓取到QQ或者其它新浪的头像。于是我自己整了一套,就是上面的代码。 接下来是小工具代码:
//读者墙 function zsofa_most_active_friends($friends_num = 10) { global $wpdb; $counts = $wpdb->get_results("SELECT * FROM (SELECT * FROM $wpdb->comments) AS tempcmt GROUP BY comment_author_email ORDER BY comment_date DESC LIMIT $friends_num"); foreach ($counts as $count) { $c_url = $count->comment_author_url; if ($c_url == '') $c_url = get_bloginfo('url'); $mostactive .= '
//读者墙reader class readerWidget extends WP_Widget { function readerWidget(){ $widget_ops = array('classname'=>'widget_reader','description'=>'侧边栏显示读者墙'); $control_ops = array('width'=>250,'height'=>300); $this->WP_Widget(false, '[FO]读者墙', $widget_ops, $control_ops); } function form($instance){ $instance = wp_parse_args((array)$instance,array('title'=>'读者墙','readerNum'=>'24'));//默认值 $title = htmlspecialchars($instance['title']); $readerNum = htmlspecialchars($instance['readerNum']); echo ''; echo ''; } function update($new_instance,$old_instance){ $instance = $old_instance; $instance['title'] = strip_tags(stripslashes($new_instance['title'])); $instance['readerNum'] = strip_tags(stripslashes($new_instance['readerNum'])); return $instance; } function widget($args, $instance){ extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('活跃读者','yang') : $instance['title']);//小工具前台标题 $title = $title; $readerNum = $instance['readerNum']; echo $before_widget; //id开始框 if( $title ) echo $before_title . $title . $after_title; //标题 if (function_exists('zsofa_most_active_friends')) { echo "
- " . zsofa_most_active_friends($readerNum) . "
register_widget('readerWidget');OK了,大功告成!
收藏的用户(0) X
正在加载信息~
推荐阅读
最新回复 (0)
站点信息
- 文章2305
- 用户1336
- 访客11461001
每日一句
Loving helps grow; liking just takes.
爱助生长,喜欢只懂索取。
爱助生长,喜欢只懂索取。
新会员