Hosico主题优化—对文章浏览量格式化

将下面代码添加至function.php文件中

function format_big_numbers($number) {
    $precision = 2;
    if ( $number >= 1000 && $number < 10000 ) {
        $formatted = number_format( $number/1000, $precision ).'K';
    } else if ( $number >= 10000 && $number < 1000000 ) {
        $formatted = number_format( $number/10000, $precision ).'W';
    } else if ( $number >= 1000000 && $number < 1000000000 ) {
        $formatted = number_format( $number/1000000, $precision ).'M';
    } else if ( $number >= 1000000000 ) {
        $formatted = number_format( $number/1000000000, $precision ).'B';
    } else {
        $formatted = $number; // Number is less than 1000
    }
    $formatted = str_replace( '.00', '', $formatted );
    return $formatted;
}

将修改Assemble.php文件中views值修改为

$info['views'] = format_big_numbers(absint(get_post_meta($post->ID, 'views', true)));

发表评论 (0)

后再参与讨论