WordPress Is The Most Popular And Powerful Content Management System. Here You Can Make Your Own Stylish Functions. WordPress Custom Post View Counter Have Some Useful Codex For Make it Yours. In this tutorial I will Show You How To output post view count without plugin.
Post Views Count
If you don’t have idea about wordpress coding php or html, simply you can do any action to your wordpress website by adding plugin. Here have more useful WordPress Plugin For Making Post View Count into your wordpress each post’s. Post Views Counter plugin help you to get each post view your wordpress post’s. The Post Views Counter Plugin Features Below.
- Option to select post types for which post views will be counted and displayed.
- 2 methods of collecting post views data: PHP and Javascript, for greater flexibility
- Possibility to manually set views count for each post
- Dashboard post views stats widget
- Capability to query posts according to its views count
- Option to set time between counts
- Excluding counts from visitors: bots, logged in users, selected user roles
- Excluding users by IPs
- Restricting display by user roles
- Restricting post views editing to admins
- One-click data import from WP-PostViews
- Sortable admin column
- Post views display position, automatic or manual via shortcode
- W3 Cache/WP SuperCache compatible
- Optional object cache support
- WPML and Polylang compatible
- .pot file for translations included
Go To Your WordPress Dashboard >>Plugins>>Add New Then Search The Post Views Counter. Setting Thing Us By Following Below Image.
For ManuallyAdding Post Views Count In WordPress Theme
First We Need To add two Functions In WordPress functions.php theme file. add the following code.
1
2
3
4
5
6
7
8
9
10
11
|
/* Count posts views */
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';
}
|
Now Add This Below Code After This Above Code.
1
2
3
4
5
6
7
8
9
10
11
12
|
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);
}
}
|
Save The Functions. Now Add This Below Code Anywhere there you want to output post views count in your wordpress theme file like single.php
1
|
<?php echo getPostViews(get_the_ID()); ?><?php setPostViews(get_the_ID());?>
|
Now Copy Past The Below Code To Your Theme File Where You Want To Display The Posts View Count Such As index.php File.
1
|
<?php echo getPostViews(get_the_ID()); ?>
|
Hope This TuTorial Will Help You. You Can Read More WordPress Tips From Below Link.
No comments:
Post a Comment