WordPress文章阅读量统计和显示(非插件, 刷新页面不累加)

WordPress文章阅读量统计实现思路:   每进入一次文章详情页面, 就会通过cookie判断该用户是否在设定的过期时间内访问过该文章, 若没有访问过, 则浏览次数增加一次。   实现流程如下:   1.添加以下代码至主题的functions.php文件, 放在该文件最下面即可: function getPostViews($postID){ $count_key = ‘views’; $count = get_post_meta($postID, $count_key, true); if($count==” || !$count){ return “0”; } return $count; } function setPostViews($postID){ $count_key = ‘views’; $count = get_post_meta($postID, $count_key, true); if($count==” || !$count) { $count = 1; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, $count); }else{ $count++; update_post_meta($postID, …