From 6b1832ce9552c148834788de4e06fad9439bb8f8 Mon Sep 17 00:00:00 2001 From: miniwater <1456441157@qq.com> Date: Tue, 12 Mar 2024 23:12:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E6=95=B0=E8=B6=85=E8=BF=87=E4=B8=80=E4=B8=87=E5=B0=B1=E9=94=99?= =?UTF-8?q?=E4=BD=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/fun/opt.php | 16 ++++++++++++++++ templates/post-actions.php | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/inc/fun/opt.php b/inc/fun/opt.php index 0173ff87..1e10eb34 100755 --- a/inc/fun/opt.php +++ b/inc/fun/opt.php @@ -34,6 +34,22 @@ function puock_post_is_like() return !empty($_COOKIE['puock_like_' . $post->ID]); } +// 点赞数显示 +function puock_post_like_num(int $id) +{ + $number = get_post_meta($id, 'puock_like', true) ?: 0; + if (!is_numeric($number)) { + $number = 0; + } + if ($number < 1000) { + return $number; // 小于1000直接返回 + } elseif ($number < 1000000) { + return round($number / 1000, 0) . 'k'; // 1000到999999之间返回“k”格式 + } else { + return round($number / 1000000, 0) . 'M'; // 大于等于1000000返回“M”格式 + } +} + //移除wp自带的widget function init_unregister_widgets() { diff --git a/templates/post-actions.php b/templates/post-actions.php index a075c432..a88e375a 100644 --- a/templates/post-actions.php +++ b/templates/post-actions.php @@ -4,7 +4,7 @@
 ID, 'puock_like', true) ?>
+ class="t-sm">ID) ?>