Not rely on WP-Statistics any more
This commit is contained in:
parent
66e58793ae
commit
a78456c595
|
@ -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 '请安装 <a href="https://wordpress.org/plugins/wp-statistics/" target="_blank">WP-Statistics 插件</a>';
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
22
options.php
22
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' => __('默认禁用,<a href="https://github.com/mashirozx/Sakura/wiki/Fancybox">请阅读说明</a>', 'options_framework_theme'),
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<span><i class="iconfont icon-mark"></i><?php comments_popup_link('NOTHING', '1 条评论', '% 条评论'); ?></span>
|
||||
</div>
|
||||
<div class="views">
|
||||
<span><i class="iconfont icon-attention"></i><?php echo wp_statistics_pages('total','uri',get_the_ID()); ?> 热度</span>
|
||||
<span><i class="iconfont icon-attention"></i><?php echo get_post_views(get_the_ID()); ?> 热度</span>
|
||||
</div>
|
||||
</div>
|
||||
</footer><!-- .entry-footer -->
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<?php if(akina_option('patternimg') || !get_post_thumbnail_id(get_the_ID())) { ?>
|
||||
<header class="entry-header">
|
||||
<h1 class="entry-title"><?php the_title(); ?></h1>
|
||||
<p class="entry-census"><?php echo poi_time_since(strtotime($post->post_date_gmt)); ?> <?php echo wp_statistics_pages('total','uri',get_the_ID()); ?> 次阅读</p>
|
||||
<p class="entry-census"><?php echo poi_time_since(strtotime($post->post_date_gmt)); ?> <?php echo get_post_views(get_the_ID()); ?> 次阅读</p>
|
||||
<hr>
|
||||
</header><!-- .entry-header -->
|
||||
<?php } ?>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<span><i class="iconfont icon-mark"></i><?php comments_popup_link('NOTHING', '1 条评论', '% 条评论'); ?></span>
|
||||
</div>
|
||||
<div class="views">
|
||||
<span><i class="iconfont icon-attention"></i><?php echo wp_statistics_pages('total','uri',get_the_ID()); ?> 热度</span>
|
||||
<span><i class="iconfont icon-attention"></i><?php echo get_post_views(get_the_ID()); ?> 热度</span>
|
||||
</div>
|
||||
</div>
|
||||
</footer><!-- .entry-footer -->
|
||||
|
|
|
@ -37,7 +37,7 @@ $the_cat = get_the_category();
|
|||
</div>
|
||||
<a href="<?php the_permalink(); ?>" class="post-title"><h3><?php the_title();?></h3></a>
|
||||
<div class="post-meta">
|
||||
<span><i class="iconfont icon-attention"></i><?php echo wp_statistics_pages('total','uri',get_the_ID()); ?> 热度</span>
|
||||
<span><i class="iconfont icon-attention"></i><?php echo get_post_views(get_the_ID()); ?> 热度</span>
|
||||
<span class="comments-number"><i class="iconfont icon-mark"></i><?php comments_popup_link('NOTHING', '1 条评论', '% 条评论'); ?></span>
|
||||
<span><i class="iconfont icon-file"></i><a href="<?php echo esc_url(get_category_link($the_cat[0]->cat_ID)); ?>"><?php echo $the_cat[0]->cat_name; ?></a>
|
||||
</span>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<span><i class="iconfont icon-mark"></i><?php comments_popup_link('NOTHING', '1 条评论', '% 条评论'); ?></span>
|
||||
</div>
|
||||
<div class="views">
|
||||
<span><i class="iconfont icon-attention"></i><?php echo wp_statistics_pages('total','uri',get_the_ID()); ?> 热度</span>
|
||||
<span><i class="iconfont icon-attention"></i><?php echo get_post_views(get_the_ID()); ?> 热度</span>
|
||||
</div>
|
||||
</div>
|
||||
</footer><!-- .entry-footer -->
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<?php the_post_thumbnail('full'); ?>
|
||||
<header class="entry-header">
|
||||
<h1 class="entry-title"><?php the_title(); ?></h1>
|
||||
<p class="entry-census"><?php echo poi_time_since(strtotime($post->post_date_gmt)); ?> <?php echo wp_statistics_pages('total','uri',get_the_ID()); ?> 次阅读</p>
|
||||
<p class="entry-census"><?php echo poi_time_since(strtotime($post->post_date_gmt)); ?> <?php echo get_post_views(get_the_ID()); ?> 次阅读</p>
|
||||
<hr>
|
||||
</header>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue