Latest Posts »
Latest Comments »
Popular Stuff (get plugin

Plugin: Stats Helper Functions And Widgets

What it does? It helps you retrieve data from wordpress.com stats and put it on your blog.

Who’s using it?

Download:

http://wordpress.org/extend/plugins/wordpresscom-stats-helper/

So far it provides helper functions and widgets to display:

  • Most Visited Posts – lists the most visited posts along with a link to the post and the views count
    • (New, Recommended) Function usage – put it into your theme template:
      if (function_exists('wpcomstats_most_visited')) {
      wpcomstats_most_visited($options);
      }

      Where:
      $options – An array which can contain the following key – value pairs:

      • posts, before, after, show_count, days – Same as before, see bellow
      • show – What type of items to display; one of ‘posts’, ‘pages’ or ‘both’
    • (Old) Function usage – put it into your theme template:
      if (function_exists('wpcomstats_most_visited_posts')) {
      wpcomstats_most_visited_posts($posts, $before,
      $after, $show_count, $days);
      }

      Where:
      $posts – Number of posts to be fetched
      $before, $after – HTML/text to put before and after each post
      $show_count – Set to false if you don’t want to display post views count
      $days – Number of days for which the stats to be calculated. Valid values: 0 (all), 1 (today), 7 (this week), 30 (this month – I know, I’m lazy but gotta KISS)

    • Widget – just drag and drop it on a sidebar.
      You can configure it’s title, the number of posts that you want to list, if to show views count for each post, for what time frame to calculate stats and if you want to restrict the lists to posts or pages only.
  • Blog Visits – shows a counter of blog visits since stats where enabled
    • Function – put in theme template:
      if (function_exists('wpcomstats_visits')) {
      wpcomstats_visits($before, $after, $post_id, $days);
      }

      Where:
      $before, $after – HTML/text to put before and after views count
      $post_id – Post/page id for which the stats must be calculated (use null for all blog stats)
      $days – Number of days for which the stats to be calculated. Valid values: 0 (all), 1 (today), 7 (this week), 30 (this month)

    • Widget – drag&drop to sidebar.
      Title is configurable, so is the timeframe for which the stats is to be calculated. The widget automagically detects single post/page contexts and shows stats for that post/page only.

Note:

  • The plugin assumes you have installed the wordpress.com stats plugin and configured it properly. If not, it will display some error messages. Pretty self descriptive.
  • The plugin caches the data from wordpress.com stats so it won’t put too much load on their system. This means visits to posts will probably not be updated in real time :)

More to come… soon! Like it, hate it?

Changes:

0.5

  • Added possibility to filter most visited items by type (post/page)
  • Added a new function for most visited items, with more flexible arguments passing
  • Safer fetching from stats.wordpress.com (try… catch)

0.4

  • Added possibility to restrict the timeframe for stats
  • Added possibility to get views count for a specific post/page (by id)

0.3:

  • Added a function and a widget for blog visits.

0.2:

  • Implemented a custom, option-based, cache for stats fetch data (on Andy’s suggestion)
  • Capped the maximum post count to 25 (you won’t be using this to spam, right?)
  • Added a configurable option for views count display

103 Comments »

103 Comments to “Plugin: Stats Helper Functions And Widgets”

  1. Caroline Says:

    Nice, I’ll use it if I can show total visits with it :-)

  2. Vlad Says:

    Thanks for the suggestion, I’ll put it in!

    BTW: I loved the Crocus pic you took a couple of days ago: http://www.flickr.com/photos/panthera_be/2312215656/

  3. Caroline Says:

    thx :-D

  4. Johnnus Says:

    Hi, your plugin does exactly what I was looking for :) … I spent a lot of time looking for this… maybe searching wrong terms but at the end I found it! :)
    But non listed in wp.org/extend why?

    Anyway, a question: I will be happy to keep reference links to this page on my blogs, but I’d like to move them from the bottom of the widgets maybe in the footer… am I allowed to do so? This will make me save much time in tuning CSS.

    Please forgive my poor english and thanks again for this plugin.

  5. Vlad Says:

    @Johnnus: Feel free to use the plugin as you wish (including any modifications)! A link back to my page is not required (unless you’re re-distributing the modified plugin) but I would very much appreciate it.

    I have applied for wp.org/extend hosting for almost a month but I guess they have a lot of requests and it takes time to activate mine.

  6. Johnnus Says:

    Thank you very much Vlad! :)

    I hope to see your plugin soon on wp.org because it deserve to be there.

    Thanks again

  7. Tim Wheatley Says:

    This looks to be exactly what I wanted. Is it possible that I could display each posts viewcount in single.php?

  8. Vlad Says:

    Not at the moment Tim, but I’ve put this in my TODO list and it’ll be soon available.

  9. Tim Wheatley Says:

    That’s awesome, thanks!

  10. Johnnus Says:

    oh-ho! 0.4! … and download from wp.org!!! Great! :D
    Good job Vlad! :)

  11. Kes Says:

    Would be sweet if this could show top posts by category ?

  12. Alex Says:

    hey Vlad

    This plugin is just what I’m looking for – however excluding pages is a must for me as my most popular posts are all pages!

    Where would I put this conditional tag to exclude pages from the output?

    Thanks again for your hard work.

  13. Vlad Says:

    Hi Alex,

    You’d have to get down&dirty and modify the source, instead of:

    $most_visited_posts .= $before.'<a href="'.$url.'" title="'.
            $name.'" rel="nofollow">'.$short_name.'</a>'.
            ($show_count?'('.$count.')':'').$after;
    

    you’ll have to put:

    $id = $cols[0];
    if (!is_page($id)) {
        $most_visited_posts .= $before.'<a href="'.$url.'" title="'.
                $name.'" rel="nofollow">'.$short_name.'</a>'.
                ($show_count?'('.$count.')':'').$after;
    }
    

    @Kes: noted!

  14. Alex Says:

    Vlad

    Thanks for your response – however the code you gave seems not to work for me. It just doesn’t output anything on the site.

    I have

    <?php wpcomstats_most_visited_posts(5, '', '', false, 7); ?>
    

    on the sidebar – when I use the plugin normally it outputs the 5 most popular posts from the week but changing the source seems to output nothing. (there’s no error messages either)

    Thanks for your time!

  15. Vlad Says:

    Alex, this was a quick hack, if all your top 5 most visited were pages then none gets displayed. Try to increase the number of posts (as pages will be removed).

  16. Alex Says:

    I do now have some posts in my top 5 so I’m not sure it’s that – to make sure I did try making it ‘20′ and the output was still blank.

  17. Vlad Says:

    Can’t really tell what’s happening, but I’ll try to release a new version soon (1-2 weeks at most) and it will cover this feature too. Stay tuned!

  18. Vlad Says:

    Updated the plugin to version 0.5 which includes filtering by type (post/page). Filtering by category didn’t make it into this version as I’m not very sure which would be the best approach yet, I’m still open for suggestion on how that would work.

  19. Richard Says:

    I love the plugin. However, when i upgraded to 0.5 i was unable to do so due to this error:

    Parse error: syntax error, unexpected ‘{‘ in /home/monarchh/public_html/wordpress/wp-content/plugins/wordpresscom-stats-helper/wpcomstats-helper.php on line 156

    Any suggestions?

  20. Vlad Says:

    Ooops! Looks like I let myself carried a bit too far, try… catch works only in PHP5. I’ll figure something out soon, thanks for dropping the note!

  21. Richard Says:

    I upgraded to PHP5 just before upgrading the plugin.

  22. Tim Wheatley Says:

    I don’t use PHP5. :(

  23. Vlad Says:

    Ok then, I updated the plugin to 0.5.2 which is PHP4-safe again!

  24. alex Says:

    Hi Vlad

    I’m getting this error now when I try and activate the new version of the plugin…

    Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /hsphere/local/home/huckftp/huckmagazine.com/wordpress/wp-content/plugins/wordpresscom-stats-helper/wpcomstats-helper.php on line 212

  25. Wardeh Says:

    Hi, I am getting this error:

    Parse error: syntax error, unexpected ‘&’, expecting T_VARIABLE or ‘$’ in /…../wp-content/plugins/wpcomstats-helper.php on line 212

    Thanks! Would love to use the plugin.

  26. Tim Wheatley Says:

    Same here.

  27. Vlad Says:

    Thanks for the feedback, it seems there was some other stuff there that’s only supported in PHP5 (passing by reference in foreach). I fixed that too and updated to v1.5.3. Sorry for the mess!

  28. Tim Wheatley Says:

    Thanks! Sorry for nagging you back to php4. :)

  29. Tim Wheatley Says:

    Vlad, can you help me out? I’m not sure where to specify posts only in this:

    wpcomstats_most_visited_posts(‘10′,”,”,’true’,'7′);

  30. Tim Wheatley Says:

    OK, all I need help in is removing pages from the stats…. But I am using your plugin for:

    The visit total (all-time) seen in the footer and the statistics page:
    http://timwheatley.org/statistics/

    The view count (all-time) seen in the left menu of each post with the text “It has been viewed x times.” like you can see here:
    http://timwheatley.org/2008/05/05/panoramic-view-of-chicago-skyline-at-dawn/
    I just had to insert the in-loop post id call into your code to bring the total for the post being viewed.

    Everything on the stats page (linked above).

    This is an awesome plugin Vlad, thanks so much!

  31. Vlad Says:

    Tim, an example on how to display only posts is in this announcement.

  32. Andrew Says:

    I have multiple blogs (2 actually) – can I combine the hits on both blogs to provide a combined count – one was a wordpress.com blog which still exists but has been superceeded by a selfhosted one. I can use the wordpress.com stats plugins to see the stats on both blogs but want to use your plugin tgo add the wordpres.com stats to the new one to give a TOTAL count – nice plugin BTW !!!

  33. Tim Wheatley Says:

    Thanks Vlad. That’s actually something new I learned. :)

    I have been editing PHP since 2001 and only now do I know the name of an array. :) When people said ‘array’ in the past I never knew what they meant, but I’ve even used them in my own code. :) That’s what you get when you learn PHP by editing existing script I guess. :D

  34. Tim Wheatley Says:

    Ok, I think I am done. Very happy! :D

    I edited the script to cut the post title length at 70 letters rather than 40, but other than that I didn’t need to change anything. Thanks again Vlad. :)

  35. Diana Says:

    Vlad, nice plugin. I was using version 0.4 without any problems. After I upgraded automatically to 0.5.3, with WordPress 2.5.1, the top posts list showed only an odd list of single digits or numbers, not the post titles, so I reverted back to version 0.4. I tried removing the widget and reinstalling it, no luck. So, I’ve restored 0.4 and will wait for another future version.

  36. Vlad Says:

    Sorry to hear that! Could you tell me more details about the settings you’re using on the widget to try and reproduce your results?

    Also, instead of removing/installing the widget, I think disabling and re-enabling the plugin would have helped more.

  37. Richard Says:

    I love the plugin.

    However, our most viewed post only comes up with the number of visits not the name of the post.

    Any thoughts on how to fix this?

  38. Ashok Varma Says:

    Hi,
    liked this tool immensely.

    Today, suddenly I got a problem.

    “Most Popular Visits” widget is working fine but “Blog Visits” widget is causing a problem.

    For all the pages/posts it is showing a single number – ‘6′.

    Please let me know what to do to fix it.

    You can check out the left side bar in http://ayaskantam.com to find this scenario.

    Regards,

    Ashok Varma

  39. Vlad Says:

    Ashok, are you running wp 2.6 by any chance? I just tested the new version and found some incompatibilities which I will fix really soon.

  40. Philix Says:

    This is a great plug in :)

  41. Diana Says:

    Hi,
    since the upgrade to WP 2.6, all data in the Most Visited Posts sidebar widget is blank. Yes, I am seeing stats from the current wordpress.com 1.3.2 stats plugin, but the Most Visited Posts plugin isn’t showing anything. I’ve tried deactivating and reactivating. Any ideas what to do?

  42. Tom Says:

    Nice plugin. Is it possible to show total visit per day and total view for all time at the same time?

  43. daniel Says:

    hi, vlad. great plugin. I used it also several weeks and after update of stats 1.3.2 I have the problem that it always tells me “.no data yet!”.

  44. daniels Says:

    going back to stats 1.2.2 and stats-helper works fine again.

  45. Damon Says:

    So stats 1.3 with this plug in wont work right? It seems to work fine if I select posts and pages, but if I just select posts I get nothing returned. Since pages are hit so much more often on our site, it doesnt help a lot since they take up the first 10 to 20 spots regularly.

  46. Richard Says:

    I have two blogs.I am using the same API key for the STATS program.

    The first one works fine and the widget shows the visits.

    The second has had very few visitors but the widget says it does not have any data.

    Any ideas?

  47. Vlad Says:

    Richard, can you post the link to that blog? I’d like to take a look!

  48. Phat^Trance Says:

    is it possible to show the pageviews on the widget and not jsut the unique visitors?

  49. Richard Says:

    This is the link:

    http://www.endinghomelessnessinnj.org/

  50. Vlad Says:

    Richard: you could check the value yourself (replace api_key with correct one, I filled the correct blog_id for you since that’s public): http://stats.wordpress.com/csv.php?api_key=api_key&blog_id=4760579&table=views&summarize=true&days=-1

    Phat_Trance: wordpress.com stats offer info about page views, that’s what the plugin shows.

  51. Richard Says:

    OK

    The key is correct in blog stats as it works there.

    I am a little confused how to do what you are suggesting?

  52. Vlad Says:

    I was suggesting to check what stats.wordpress.com is reporting directly (using the given link). Then we know if it’s a problem with the plugin or the stats service.

  53. Richard Says:

    OK.

    I will try to do that.

    Stats is workign as I can see numbers on the dashboard. The only place i cannnot see them is the plugin.

  54. Richard Says:

    on occassion i do get stats and then they disappear. As it is a new site I only have 41 hits. Is that an issue?

    Can you check out the site?

    http://www.njaneh.org

  55. Dan Says:

    Hi Vlad
    Thanks for the plugin – question: Is it possiblt to edit ‘blog visits’ field so that only blog visits after aug 31 2008 are counted?
    thanks

  56. Amila Jašarević Says:

    Hi Vlad, your plug in was just what I was looking for. But I can’t get it to only show posts. If I set the widget that way, nothing is shown except the widget title. I’ve tried to change around some code as you’ve written earlier in this thread, but no success. Any ideas?

  57. Michael Tyson Says:

    If you’ll forgive my presumption to modify your code, I made some improvements after realising your plugin wasn’t working on my WP 2.6.2 site when selecting to show posts only. The plugin was just displaying no results at all, because it was using an empty string for the ‘include’ part of the post query, instead of ‘any’, which it should’ve been.

    I also made some improvements to the interface, adding defaults, replacing a drop-down used for a boolean value with a checkbox, and adding the option to truncate titles or not, and the option to display or not display the link to the plugin.

    I’ve temporarily uploaded a zip file containing the new version as well as a patch showing the changes to http://michael.tyson.id.au/wpcomstats-helper-0.5.5.zip . Tell me when you’ve downloaded it and I shall remove it.

    Let me know what you think.

  58. Vlad Says:

    Thanks Michael!

    I downloaded the file and I’ll have a look at the code as soon as possible.

    Any contributions to the plugin are always welcome!

  59. baron Says:

    hi. Thanks for plugin

    perfect.

    Regards

  60. Blackwings Says:

    Any word on a fix for Wordpress version 2.6.2? Ever since the upgrade my most viewed posts have stopped reporting – it just shows nothing.

    I’ve upgraded my code to the newest recommended array format but no change.

  61. Vlad Says:

    You are using the latest version of the plugin, right? Please also try a disable/enable cycle for the plugin (clears the cache)!

  62. Yuval Says:

    same here.
    Ever since i updated the plugin i have not got it to work.
    Disable/Enable were done but no help.
    The code to call the script was changed to the array one.
    No list at the moment.

  63. Vlad Says:

    Yuval, your problem might be solved if you make sure your $options['show'] has one of the ‘post’, ‘page’ or ‘both’ values set. There’s a missing default there that’s been causing people a headache. Let me know how this works out!

  64. Alfonso Says:

    I’ve got the same problem, the “Most Read Posts” list isn’t working any more. Buggy release? :-P

  65. Yuval Says:

    Thanks, that worked!

  66. Leo Says:

    Hi Vlad,

    Same case here. The plugin isn’t working since last update.

  67. Vlad Says:

    I added a default for $options['show'] – please see version 0.5.5.2

  68. CzechFolks Says:

    I switched from wordpress.com to hosting through bluehost. I downloaded your plugin but it only gives me stats after I switched to the new hosting service. Is there a way to combine both stats? I used the same API code but the WP.com stats table gives me a choice to select between these two sites but not one that combines all stats.
    Thanks.

  69. Vlad Says:

    Stats are recorded separately for different URLs. Since I supposed you’ve changed the URL while moving from wp.com to your own domain and hosting, there’s nothing you can do about it (unless you can convince the wp.com stats team to move your old stats to your new URL).

  70. CzechFolks Says:

    Yes, that makes sense. Thank you very much!

  71. IndoS Says:

    Vlad, I’m following your installation, but I can’t seem to get blog visits working… most visited works just fine.
    I’ve installed the wordpress stats. Any ideas? Thanks

  72. Vlad Says:

    It’s not working as in: it doesn’t show anything or it shows wrong data/error? Can you send me a link to your site so I can check out the behaviour?

  73. IndoS Says:

    it shows that ‘There’s No Data Yet’. I already had many visits so, this is surely wrong. Thanks for the help. I really appreciate it. This is such a good plugin.

    http://howtogeta40.clicknsmart.com

  74. Alfonso Says:

    Still no luck, the newer version continue to hide the “Most Visited Posts” thingy…

    Reverting to 0.5.4 once again….

  75. D&CW's Says:

    Hey there, I’ve the same problem like IndoS. It shows: “There’s no data yet.”

    The wordpres.com/stats plugin is up and running for over 2 months now and there are some visits.

    At the moment I’ve got 2 blogs running on 1 API. Mayby that is the problem??

  76. Tracy Sanchez Says:

    I’ve installed the plugin and added the “most visited post” widget.

    on my page you can see “Top Post”, but no post or links are showing up.

    Do I need to add this code and if so, where exactly does this code need to go?

    if (function_exists(‘wpcomstats_most_visited’)) {
    wpcomstats_most_visited($options);
    }

  77. Prachi Says:

    I have installed wordpress stats plugin and wordpress stats helper plugin. Both of them are installed properly and I can see stats my dashboard. Now I want display most visited post in tab . So I am using this following code
    wpcomstats_most_visited($options = array (
    ‘posts’ => 10,
    ‘before’ => ”,
    ‘after’ => ”,
    ’show_count’ => false,
    ‘days’ => 30,
    ’show’ => posts
    ));
    but nothing is displayed. Can you please help me this

  78. Tracy Sanchez Says:

    Nevermind my question as it seems to be working now.

  79. Kitta Says:

    I’ve had the Stats Helper plugin installed for a few months at the bottom of my blog to display a counter of visits/hits. It was working fine until recently when an error appeared…

    Warning: Invalid argument supplied for foreach() in /wp-content/plugins/wpcomstats-helper.php on line 107

    However it still displays the hits/view count after the error. I’ve tried to tinker a few things but nothing seemed to help. Any ideas?

  80. Vlad Says:

    Thanks for pointing that out. I just made a fix and it should soon be available as version 0.5.5.3

  81. baron Says:

    Works great, thank you

  82. prachi Says:

    Hi Vlad,
    Thanks for developing this wonderful plugin.
    I wanted to use this plugin to display most viewed post on my website http://www.asianweek.com
    I have installed wordpress stats plugin and wordpress stats helper plugin.I can see the stats appearing on my dashboard but however i cannot see the stats on my Most viewed section. here my code. Most Viewed

    Please let me know where i am going wrong
    Thank you in advance

  83. Time Synchronisation Says:

    This is a great plug in :)

  84. Sean Says:

    Hey there, just installed your plugin and it’s awesome. Short, sweet & simple.

    I’m trying to modify it to display top categories (i.e. count the total views for each category) but I’m struggling. Any tips or suggestions on where/how to start?

    Cheers

  85. Moises Says:

    Hi,

    Sometimes instead of getting the data that I was supposed to get, it displays the last posts.

    Any ideas why that happens? For me it seams to be completely random.

  86. Richard Says:

    My problem may not be solvable.

    I upgraded and accidently created a second site with stats. Both have the same name. How can I fix this so that my stats will not only work but reflect my entire history?

  87. Vlad Says:

    Richard, what do you mean by “accidently created a second site with stats”? A new API key or a new blog id?

    For all things related to API keys, blog IDs and stats merging I think you should talk to the wp.com support.

  88. Alfonso Says:

    Tried to update to 0.5.5.3, no luck once again: the plug-in continues to not to show the “most read posts”. Disappointing…

    Reverting back to 0.5.4 for the third time….

  89. Alex Says:

    Love the plugin and it was exactly what I wanted.

    Would it be possible to filter my categories and have multiple instances in the sidebar?

  90. Cristi Jugariu Says:

    ma intereseaza sa imi apara doar vizitele totale. Nu am sidebar. Ce cod trebuie sa scriu?

  91. Vlad Says:

    Cristi: to display all visits to your blog you can use:


    if (function_exists('wpcomstats_visits')) {
    wpcomstats_visits('', '', null, 0);
    }

    in your template.

  92. Cristi Jugariu Says:

    And if I get: No data yet! it means it does not display the visits I have previously installing this plugin?

  93. Vlad Says:

    This plugin uses data from the Wordpress.com stats plugin. If you installed that recently, it’s normal to get “No data yet!”.

  94. Cristi Jugariu Says:

    I have it installed few months ago… in June last year…

  95. jaggerkieth Says:

    Is this plugin support wp 2.7.1?

  96. Vlad Says:

    Yes, it works with wp 2.7.1. Actually, this site is using that version.

  97. jaggerkieth Says:

    Is there any way to put a txt after the blog visits? And can I remove the link? It doesnt look nice on my site.

  98. Gary Pendergast Says:

    This is pretty close to what I need, but are you looking at extending it? In particular, I’m after an interface for the most popular search terms.

  99. Michael Says:

    I am trying to tweak your code, changing the results maximum from 25, to 50. But even when changed, it still only returns 50. Is this a setting locked from wordpress.com? Any ideas?

  100. RaiulBaztepo Says:

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

Leave a Comment


Running on Mojito Software