0

我在 wordpress 主题中有这个功能:

// function to count views.
function setPostViews_anthemes($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}    

我需要查看次数显示从 1 到 999 的随机数

4

1 回答 1

1

1999在 PHP 中使用to 生成随机整数rand(1,999)

// function to count views.
function setPostViews_anthemes($postID) {
    $count_key = 'post_views_count';
    $count = rand(1,999);   
    update_post_meta($postID, $count_key, $count);
}
于 2016-06-03T17:38:59.707 回答