diff --git a/functions.php b/functions.php index f13add1..7d94379 100644 --- a/functions.php +++ b/functions.php @@ -440,15 +440,29 @@ if(!function_exists('akina_comment_format')){ } /** - * post views. - * @bigfa + * post views */ function restyle_text($number) { - if($number >= 1000) { - return round($number/1000,2) . 'k'; - }else{ - return $number; + switch (akina_option('statistics_format')) { + case "type_2": //23,333 次访问 + return number_format($number); + break; + case "type_3": //23 333 次访问 + return number_format($number, 0, '.', ' '); + break; + case "type_4": //23k 次访问 + if($number >= 1000) { + return round($number/1000,2) . 'k'; + }else{ + return $number; + } + break; + default: + return $number; } + + + } function set_post_views() { @@ -466,18 +480,23 @@ function set_post_views() { add_action('get_header', 'set_post_views'); function get_post_views($post_id) { - /* 修改需配合统计插件 - * $count_key = 'views'; - * $views = get_post_custom($post_id); - * $views = intval($views['views'][0]); - * $post_views = intval(post_custom('views')); - * if($views == '') { - * return 0; - * }else{ - * return restyle_text($views); - * } - */ - return wp_statistics_pages('total','uri',$post_id); + if (akina_option('statistics_api')=='wp_statistics'){ + if (!function_exists(wp_statistics_pages)) { + return '请安装 WP-Statistics 插件'; + } else { + return restyle_text(wp_statistics_pages('total','uri',$post_id)); + } + } else { + $count_key = 'views'; + $views = get_post_custom($post_id); + $views = intval($views['views'][0]); + $post_views = intval(post_custom('views')); + if($views == '') { + return 0; + }else{ + return restyle_text($views); + } + } } diff --git a/options.php b/options.php index ec192ab..1849610 100644 --- a/options.php +++ b/options.php @@ -924,6 +924,28 @@ function optionsframework_options() { 'std' => '', 'type' => 'text'); + $options[] = array( + 'name' => __('统计接口', 'akina'), + 'id' => 'statistics_api', + 'std' => "theme_build_in", + 'type' => "radio", + 'options' => array( + 'wp_statistics' => __('WP-Statistics 插件(专业性统计,可排除无效访问)', ''), + 'theme_build_in' => __('主题内建(简单的统计,计算每一次页面访问请求)', '') + )); + + $options[] = array( + 'name' => __('统计数据显示格式', 'akina'), + 'id' => 'statistics_format', + 'std' => "type_1", + 'type' => "radio", + 'options' => array( + 'type_1' => __('23333 次访问(默认)', ''), + 'type_2' => __('23,333 次访问(英式)', ''), + 'type_3' => __('23 333 次访问(法式)', ''), + 'type_4' => __('23k 次访问(中式)', ''), + )); + $options[] = array( 'name' => __('启用 baguetteBox', 'options_framework_theme'), 'desc' => __('默认禁用,请阅读说明', 'options_framework_theme'), diff --git a/tpl/content-image.php b/tpl/content-image.php index cc71758..2849885 100644 --- a/tpl/content-image.php +++ b/tpl/content-image.php @@ -35,7 +35,7 @@
post_date_gmt)); ?> 次阅读
+post_date_gmt)); ?> 次阅读
post_date_gmt)); ?> 次阅读
+post_date_gmt)); ?> 次阅读