Show views posts without plugin in wordpress
In this article I will guide you to see the number of people viewing your posts in wordpress, surely you will want to know if the article is the most heavily visited, is most concerned about right.
This way without the use of plugins, very fast, you do not lose too much time in this post where.
It’s easy to do, how we begin. You copy this code and paste into the functions.php file offline
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);
}
}
Next open your single.php file and paste the following code:
You can refer to the figure below to set the correct code you want to put
The code above is just the constructor, to show, you should call the following command and placed in any position that you want to display.
You can also create the same functionality with the plugin also but it weighs your site and one that is important …. not prooooo …
Wish you success.
Dùng thế nào trên childtheme genesis vậy bạn