Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there any currently supported plugin to display the number of page views on a post? wp-postviews seems to be the most commonly used, but it requires modifying the theme (which would require creating a child theme to avoid being overwritten by theme updates), and does not seem to work with caching plug-ins.

It seems like this should be straight-forward to extend the wp-statistics / jetpack API to display this information, but I haven't found a plugin that will do so. Seems like a common feature, surely this has been done somewhere?

share|improve this question
add comment

4 Answers 4

wp-postviews seems to be the most commonly used, but it requires modifying the theme (which would require creating a child theme to avoid being overwritten by theme updates) ...

If you want to actually display the view count on the post but this item isn't built in to your theme already, then you're going to have to edit your theme or create a child theme. There's no way around that.

...and does not seem to work with caching plug-ins.

If you're wanting to display a dynamic view count on a post, using caching isn't necessarily a good idea.

Most caching systems return static HTML content in place of a dynamically-generated page. This means the counter wouldn't increment with each page load unless you force the cache to refresh at a set interval ... and then the counter would only chance when that refresh occurred.

Seems like a common feature, surely this has been done somewhere?

It has, and you've already found one of the ways people have been doing it - WP-PostViews

There are a few other plugins out there that do the same thing, since you've already found one I assume you can find the others pretty quickly as well.

share|improve this answer
    
Thanks for this reply, was definitely helpful. I am confused though - other plugins display content on pages without requiring a child theme - (e.g. kcite, post revision display). It seems the plugin Ajax-the-Views addresses the caching issue. Would be nice if wp-postviews or other option used the wp-stats api so it would match those statistics, rather than starting at zero. –  cboettig Nov 17 '11 at 16:35
    
Most plugins that display content will hook in to the content filter or another filter in WP and inject HTML markup directly in the page. Some times this works just fine. Other times it can cause the layout of your site to explode. It all depends on what theme you're using and how it's coded. The safest route is to use a child theme so other developers aren't blindly guessing where the markup will fit with the rest of your site. –  EAMann Nov 17 '11 at 17:16
add comment

Try this Works on single site

// post views
function setAndViewPostViews($postID) {
    $count_key = 'views';
    $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);
    }
    return $count; /* so you can show it */
}

You need to add the following function to your theme's functions.php and call it inside the loop or inside your posts.php or page.php of your theme. like so

<?php echo setAndViewPostViews(get_the_ID());  ?>

This will increment and persist the post's count then show the number of views.

Got inspiration from the question and did a write up if it might help anyone http://nerudo.mregi.com/how-to-display-number-of-page-views-on-a-post-wp/

share|improve this answer
    
thanks - can you provide more details? Which file are you editing? Does this require plugins? I assume you need to then create a child-theme to avoid these changes being over-written? Thanks. –  cboettig Dec 6 '11 at 16:51
add comment
up vote 0 down vote accepted

Using WP-PostViews with Ajax-the-Views and a child theme for both the index.php and single.php files of my theme is the best solution I have at the moment.

Pity that this does not call the wp-stats API with my API key, so that the counters would not start at zero but reflect the history stored by the stats plugin.

Thanks @EAMann for suggestions, and happy to hear of other solutions.

share|improve this answer
add comment

Does this work for you? http://wordpress.org/extend/plugins/jetpack-post-views/ It was released yesterday.

share|improve this answer
1  
Hi, Cliff, please add a summary from the external site, see this faq section. –  brasofilo Jan 22 '13 at 17:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.