//转自:http://wpsnipp.com/index.php/functions-php/track-post-views-without-a-plugin-using-post-meta/
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;
}
return intval($count);
}
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);
}
}
//在文章显示的模板页面添加下面的代码
setPostViews( $post_id );
//得到点击数量的方法
getPostViews( $post_id );