ripro添加自动随机文章阅读次数
位置:riproinctheme-functions.php
搜索 post 文章阅读次数 找到以下代码
原本未修改的代码
/**
* post 文章阅读次数
*/
function _post_views_record()
{
if (is_singular()) {
global $post;
$post_ID = $post->ID;
if ($post_ID) {
$post_views = (int) get_post_meta($post_ID, \'views\', true);
if (!update_post_meta($post_ID, \'views\', ($post_views + 1))) {
add_post_meta($post_ID, \'views\', 1, true);
}
}
}
}
function _get_post_views($before = \'\', $after = \'\')
{
global $post;
$post_ID = $post->ID;
$views = (int) get_post_meta($post_ID, \'views\', true);
if ($views >= 1000) {
$views = round($views / 1000, 2) . \'K\';
}
return $before . $views . $after;
}
将以下代码替换上面原本的代码即可
/**
* post 文章阅读次数
*/
function _post_views_record()
{
if (is_singular()) {
global $post;
$post_ID = $post->ID;
if ($post_ID) {
$post_views = (int) get_post_meta($post_ID, \'views\', true);
$min = 128;
$max = 863;
//如果阅读量小于$min,则自动计算一个$min~$max的随机数作为阅读量
if($post_views<$min){
$post_views=rand($min,$max);
}
if (!update_post_meta($post_ID, \'views\', ($post_views + 1))) {
add_post_meta($post_ID, \'views\', 1, true);
}
}
}
}
function _get_post_views($before = \'\', $after = \'\')
{
global $post;
$post_ID = $post->ID;
$views = (int) get_post_meta($post_ID, \'views\', true);
if ($views >= 1000) {
$views = round($views / 1000, 2) . \'K\';
}
return $before . $views . $after;
}