在单个站点上尝试thisWorks
// post views
function setAndViewPostViews($postID) {
$count_key = \'views\';
$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);
}
return $count; /* so you can show it */
}
您需要将以下函数添加到主题的函数中。php并在循环或帖子中调用它。php或页面。主题的php。就像这样
<?php echo setAndViewPostViews(get_the_ID()); ?>
这将增加并保持帖子的计数,然后显示视图的数量。
从这个问题中获得灵感,并写了一篇文章,如果它对任何人都有帮助的话http://nerudo.mregi.com/how-to-display-number-of-page-views-on-a-post-wp/