diff --git a/README.md b/README.md index c9814ce..c8bb30f 100755 --- a/README.md +++ b/README.md @@ -1,26 +1,2 @@ -# Adams - -一套适用于 WordPress 的简洁、轻量的 Theme - - -# 发行 - -Github 默认为开发版,如果需要稳定发行版,请前往:https://github.com/Tokinx/Adams/releases - -下载后进入 WordPress 后台进行安装并启用即可 - -主题设置项在:后台 -> 主题 -> 自定义 - -# 如何贡献 - -合理的改动的PR都会被合并,合理的 issues 都会被采纳并修改。 - -# 鸣谢 - -维护:[Tokin](https://biji.io) - -贡献:[@Frank](https://github.com/w4o)、[@Abdul Wahab](https://github.com/abdulwahab610)、[@Sammy Liang](https://github.com/SammyLiang97)、[@刘明野](https://github.com/liumingye)、[@lizhimiao](https://github.com/zhimiaoli)、[@keinx](https://github.com/keinx) - -# 讨论 - -https://github.com/Tokinx/Adams/issues +基于: https://github.com/Tokinx/Adams/ +添加了阅读量和字数统计功能 diff --git a/functions.php b/functions.php index b8bc8e5..d807fb6 100755 --- a/functions.php +++ b/functions.php @@ -590,3 +590,51 @@ public function toWpFormat() ); // 全部配置完毕 + +//阅读数量计算 +function get_post_views ($post_id) { + + $count_key = 'views'; + $count = get_post_meta($post_id, $count_key, true); + + if ($count == '') { + delete_post_meta($post_id, $count_key); + add_post_meta($post_id, $count_key, '0'); + $count = '0'; + } + + echo number_format_i18n($count); + +} + +function set_post_views () { + + global $post; + + $post_id = $post -> ID; + $count_key = 'views'; + $count = get_post_meta($post_id, $count_key, true); + + if (is_single() || is_page()) { + + if ($count == '') { + delete_post_meta($post_id, $count_key); + add_post_meta($post_id, $count_key, '0'); + } else { + update_post_meta($post_id, $count_key, $count + 1); + } + + } + +} +add_action('get_header', 'set_post_views'); + +//字数统计 +function count_words ($text) { +global $post; +if ( '' == $text ) { + $text = $post->post_content; + if (mb_strlen($output, 'UTF-8') < mb_strlen($text, 'UTF-8')) $output .= '本文共' . mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8') . '个字'; + return $output; +} +} diff --git a/header.php b/header.php index f9d4d43..df07334 100755 --- a/header.php +++ b/header.php @@ -58,7 +58,9 @@
- \ No newline at end of file + diff --git a/index.php b/index.php index 99660b5..954c4dc 100755 --- a/index.php +++ b/index.php @@ -28,6 +28,7 @@