From e7df4d13f944ae0672fae95b6aeddfb65eccb432 Mon Sep 17 00:00:00 2001 From: cc2007 <88186750+cc2007@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:45:36 +0800 Subject: [PATCH 1/7] Update functions.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新阅读数量计算 --- functions.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/functions.php b/functions.php index b8bc8e5..89ef923 100755 --- a/functions.php +++ b/functions.php @@ -590,3 +590,41 @@ 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'); From 609bb84ee3da1aaf84f024e3e116b39ad6933c99 Mon Sep 17 00:00:00 2001 From: cc2007 <88186750+cc2007@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:48:10 +0800 Subject: [PATCH 2/7] Update index.php --- index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/index.php b/index.php index 99660b5..954c4dc 100755 --- a/index.php +++ b/index.php @@ -28,6 +28,7 @@