我在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);
}
}
我需要viws的数量显示从1到999的随机数
答案 0 :(得分:1)
要在PHP中生成从1
到999
的随机整数,请使用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);
}