在功能中。php输入此代码
function getPostViews($postID){
$count_key = \'post_views_count\';
$count = get_post_meta($postID, $count_key, true);
if($count==\'\'){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, \'0\');
return "0 View";
}
return $count.\' Views\';}
function setPostViews($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);
}}
然后是单曲。php放入此代码
<?php
setPostViews(get_the_ID());
?>
若要显示视图计数,请将此代码放在所需的任何位置<span class="views"><?php
echo getPostViews(get_the_ID());
?></span> |
这将计算每次访问该帖子的次数,您可以将其放入循环中。php/索引。phpto查看每个帖子视图