// // 定义小工具的类 WordPressRunningInfoStat class WordPressRunningInfoStat extends WP_Widget{ function WordPressRunningInfoStat(){ // 定义小工具的构造函数 $widget_ops = array('classname' => 'widget_blogstat', 'description' => '显示博客的统计信息'); $this->WP_Widget(false, '博客统计', $widget_ops); } function form($instance){ // 表单函数,控制后台显示 // $instance 为之前保存过的数据 // 如果之前没有数据的话,设置默认量 $instance = wp_parse_args( (array)$instance, array( 'title' => '博客统计', 'establish_time' => '2016-09-28' ) ); $title = htmlspecialchars($instance['title']); $establish_time = htmlspecialchars($instance['establish_time']); // establish_time => 建站日期 // 表格布局输出表单 $output = ''; $output .= '
标题'; $output .= ''; $output .= '
建站日期:'; $output .= ''; $output .= '
'; echo $output; } function update($new_instance, $old_instance){ // 更新数据的函数 $instance = $old_instance; // 数据处理 $instance['title'] = strip_tags(stripslashes($new_instance['title'])); $instance['establish_time'] = strip_tags(stripslashes($new_instance['establish_time'])); return $instance; } function widget($args, $instance){ extract($args); //展开数组 $title = apply_filters('widget_title',empty($instance['title']) ? ' ' : $instance['title']); $establish_time = empty($instance['establish_time']) ? '2013-01-27' : $instance['establish_time']; echo $before_widget; echo $before_title . $title . $after_title; echo '
'; echo $after_widget; } function efan_get_blogstat($establish_time /*, $instance */){ // 相关数据的获取 global $wpdb; $count_posts = wp_count_posts(); $published_posts = $count_posts->publish; $draft_posts = $count_posts->draft; $comments_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments"); $time = floor((time()-strtotime($establish_time))/86400); $count_tags = wp_count_terms('post_tag'); $count_pages = wp_count_posts('page'); $page_posts = $count_pages->publish; $count_categories = wp_count_terms('category'); $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); $last = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')"); $last = date('Y-m-d', strtotime($last[0]->MAX_m)); $total_views = $wpdb->get_var("SELECT SUM(meta_value+0) FROM $wpdb->postmeta WHERE meta_key = 'views'"); $uptime = trim(file_get_contents('/proc/uptime')); $uptime = explode(' ', $uptime); $uptime = $uptime[0]; $uptime = round($uptime / 86400, 2); $this->statItem('fa fa-file', '文章数量', $published_posts); $this->statItem('fa fa-comments', '评论数量', $comments_count); $this->statItem('fa fa-tags', '标签数量', $count_tags); $this->statItem('fa fa-clock-o', '建站日期', $establish_time); $this->statItem('fa fa-battery-full', '累计安全运行', $time . ' 天'); $this->statItem('fa fa-power-off', '自上次服务重启后持续运行', $uptime . ' 天'); $this->statItem('fa fa-clock-o', '最后更新', $last); } function statItem($fa, $desc, $data) { echo '
  • '; echo ''; echo '' . $data . ''; echo ' ' . $desc. ' '; echo '
  • '; } } function WordPressRunningInfoStat(){ // 注册小工具 register_widget('WordpressRunningInfoStat'); } add_action('widgets_init','WordpressRunningInfoStat'); ?>
    ( ! ) Warning: session_start(): Cannot start session when headers already sent in D:\wamp64\www\wp-content\themes\ripro\inc\theme-functions.php on line 2638
    Call Stack
    #TimeMemoryFunctionLocation
    10.0001410808{main}( )...\index.php:0
    20.0001411080require( 'D:\wamp64\www\wp-blog-header.php' )...\index.php:17
    30.0001411432require_once( 'D:\wamp64\www\wp-load.php' )...\wp-blog-header.php:13
    40.0002412112require_once( 'D:\wamp64\www\wp-config.php' )...\wp-load.php:37
    50.0002413360require_once( 'D:\wamp64\www\wp-settings.php' )...\wp-config.php:90
    67.18556758072do_action( )...\wp-settings.php:540
    77.18556758448WP_Hook->do_action( )...\plugin.php:478
    87.18566758448WP_Hook->apply_filters( )...\class-wp-hook.php:311
    97.22307507424wp_widgets_init( )...\class-wp-hook.php:287
    107.22617537120do_action( )...\widgets.php:1765
    117.22617537496WP_Hook->do_action( )...\plugin.php:478
    127.22617537496WP_Hook->apply_filters( )...\class-wp-hook.php:311
    137.22617538624caozhuti_widgets_init( )...\class-wp-hook.php:287
    147.22617538624is_cao_site_list_blog( )...\functions.php:153
    157.22617538624session_start ( )...\theme-functions.php:2638

    ( ! ) Warning: Cannot modify header information - headers already sent by (output started at D:\wamp64\www\wp-content\themes\ripro-child\tongji.php:57) in D:\wamp64\www\wp-includes\pluggable.php on line 1281
    Call Stack
    #TimeMemoryFunctionLocation
    10.0001410808{main}( )...\index.php:0
    20.0001411080require( 'D:\wamp64\www\wp-blog-header.php' )...\index.php:17
    38.652715086632require_once( 'D:\wamp64\www\wp-includes\template-loader.php' )...\wp-blog-header.php:19
    48.652715086632do_action( )...\template-loader.php:13
    58.652715087008WP_Hook->do_action( )...\plugin.php:478
    68.652715087008WP_Hook->apply_filters( )...\class-wp-hook.php:311
    78.654715151200redirect_canonical( )...\class-wp-hook.php:287
    88.657615156072wp_redirect( )...\canonical.php:615
    98.657715156128header ( )...\pluggable.php:1281

    ( ! ) Warning: Cannot modify header information - headers already sent by (output started at D:\wamp64\www\wp-content\themes\ripro-child\tongji.php:57) in D:\wamp64\www\wp-includes\pluggable.php on line 1284
    Call Stack
    #TimeMemoryFunctionLocation
    10.0001410808{main}( )...\index.php:0
    20.0001411080require( 'D:\wamp64\www\wp-blog-header.php' )...\index.php:17
    38.652715086632require_once( 'D:\wamp64\www\wp-includes\template-loader.php' )...\wp-blog-header.php:19
    48.652715086632do_action( )...\template-loader.php:13
    58.652715087008WP_Hook->do_action( )...\plugin.php:478
    68.652715087008WP_Hook->apply_filters( )...\class-wp-hook.php:311
    78.654715151200redirect_canonical( )...\class-wp-hook.php:287
    88.657615156072wp_redirect( )...\canonical.php:615
    98.671915156200header ( )...\pluggable.php:1284