Skip to content

Commit

Permalink
优化了点赞数超过一万就错位的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
miniwater committed Mar 12, 2024
1 parent 654ebe8 commit 6b1832c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions inc/fun/opt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion templates/post-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="circle-button puock-bg text-center <?php if (puock_post_is_like()): ?>bg-primary text-light<?php endif; ?>"
id="post-like" data-id="<?php the_ID() ?>">
<i class="fa-regular fa-thumbs-up t-md"></i>&nbsp;<span
class="t-sm"><?php echo get_post_meta($post->ID, 'puock_like', true) ?></span></div>
class="t-sm"><?php echo puock_post_like_num($post->ID) ?></span></div>
<?php if (pk_is_checked('post_poster_open')): ?>
<div class="circle-button puock-bg text-center pk-modal-toggle"
title="海报" data-no-title data-no-padding data-once-load="true"
Expand Down

0 comments on commit 6b1832c

Please sign in to comment.