OnlineEarning .Blog

The OnlineEarning .Blog is a blog about Making Money Online through various legitimate ways, specially using a blog. The creator of this site makes money online and lives a good life after leaving his day job. If you run a blog, you too can make money. All you need is a little bit of guidance in the beginning. That's why http://onlinearningjob.blogspot.com/ is here for you! Take a look, browse through the pages and start earning a decent living off your blog(s)

Search

ONLINE EARNING MONEY

ONLINE JOBS

MONEY BANK

ONLINE MONEY

EARN MONEY

EARN 4 YOUTH

Show Post Views Count on Posts in WordPress

I have seen many premium WordPress themes showing Post views count right below Posts and i thought that its only for premium themes but when i find about this topic on internet i found that its very easy to show post views count on any WordPress blog. Again thanks to the WordPress plugins which make our lives easier. But for those who don’t like to use too many plugin’s on there blog there is also a direct code which you have to put into your theme files. Showing post views will be a nice thing to do as it help readers to select popular post based on views.
Show Post Views Count on Posts in WordPress
WordPress PostViews Plugin.
The easiest way to show post views count is obviously via installing plugin. The plugin we use is WP-PostViews which you can download from official WordPress website by clicking here. Download the plugin, install it and than activate it. Now go to WP-Admin -> Settings -> PostViews and configure the plugin options.
Now comes the second part. Open your theme’s single.php file or any file where you want to display the post views count and search for the heading code.
<?php the_title(); ?>
Now right below this code add following code and update the file.
<?php if(function_exists(‘the_views’)) { the_views(); } ?>
Refresh your blog and you will see post views count on posts starting from zero.
Show Post Views Count on Posts without Plugin.
Now for those who hate plugins like me there is a piece of code for you through which you can easily show post views count on any page. First of all open your blog theme’s functions.php file and paste the following code in it.
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);
    }
}
Now open single.php file and paste the following code right after while loop.
<?php setPostViews(get_the_ID()); ?>
To display the post view count simply paste the code where you want to actually display the post views count.
<?php echo getPostViews(get_the_ID()); ?>
That’s it very easy and simple way to display post views count in any page in WordPress blog.
source