wordpress本身不带文章浏览统计,可以用插件wp-postview,但是刷新还是算一个浏览次数。
1.首先在主题下functions.php里增加以下代码,这段代码也是网上可以找到的
1 //add by charleswu 2 function getPostViews($postID) { 3 $count_key = 'post_views_count'; 4 $count = get_post_meta($postID, $count_key, true); 5 if ($count == '') { 6 delete_post_meta($postID, $count_key); 7 add_post_meta($postID, $count_key, '0'); 8 return "0"; 9 }10 return $count;11 }12 function setPostViews($postID) {13 $count_key = 'post_views_count';14 $count = get_post_meta($postID, $count_key, true);15 if ($count == '') {16 $count = 0;17 delete_post_meta($postID, $count_key);18 add_post_meta($postID, $count_key, '0');19 } else {20 $count++;21 update_post_meta($postID, $count_key, $count);22 }23 }