使用以下代码段跟踪wordpress博客上的帖子视图。您要做的第一件事是将此代码段添加到函数中。wordpress主题的php。遵循步骤1。和步骤2。跟踪和显示每篇文章的视图数。这篇文章的作者
http://wpsnipp.com/index.php/cache/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 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);
}
}
// Remove issues with prefetching adding extra views
remove_action( \'wp_head\', \'adjacent_posts_rel_link_wp_head\', 10, 0);