WordPress.com Popular Posts

WordPress.com Popular Posts integrates with Wordpress.com Stats plugin, providing a widget to show the most viewed posts.

Installation

  • Install Wordpress.com Stats plugin (required at least v1.2!!!)
  • Download Wordpress.com Popular Posts v1.1.2
  • Extract the files in the .zip archive, and upload them (including subfolders) to your /wp-content/plugins/ directory
  • Activate the plugin through the ‘Plugins’ menu in WordPress
  • Place the widget where you like in your sidebars
  • Enjoy!

Themes Integration

If your theme supports widgets, you can place the widget named ‘Popular Posts’ where you want.

If it doesn’t, put this code inside the file sidebar.php, in your theme files:

Optionally you can add some parameters to the function, in this format:

name=value&name=value etc.

Possible names are:

  • title (title of the widget, you can add tags (e.g. <h3>Popular Posts</h3>) default: Popular Posts)
  • number (number of links shown, default: 5)
  • days (length of the time frame of the stats, default 0, i.e. infinite)
  • show (what you want to show; it can be: both, posts, pages; default is both)
  • format (the format of the links shown, default: <a href='%post_permalink%' title='%post_title%'>%post_title%</a>)

You can use these special markers in the format value:

  • %post_permalink% the link to the post
  • %post_title% the title the post
  • %post_title_attribute% the title of the post; use this in attributes, e.g. <a title='%post_title_attribute%'...
  • %post_views% number of views
Example

If you want to show the widget without any title, the 3 most viewed articles, in the last week, and in this format: My Article (123 views) you will use this:

<?php WPPP_show_popular_posts( "title=&number=3&days=7&format=<a href='%post_permalink%' title='%post_title_attribute%'>%post_title% (%post_views% views)</a>" );?>

Changelog
  • 1.1.2 - Added a fix for a bug in WordPress Stats.
  • 1.1.1 - Fixed some unclosed tags, which caused issues in IE7 configuration of the widget.
    Removed (actually it's only skipped, not fixed yet) a nasty MySQL error if there aren't any "top posts".
  • 1.1 - New feature: now you can choose to show only posts, only pages, or both (default).
  • 1.0.1 - Added CSS class "wppp_list", so that you can now customize the styling in your stylesheet.
  • 1.0 - Feature: now you can customize the format of the links (see docs above)
    Feature: it's now possible to show the number of views of the post (see docs above)
    Fix: fixed utf-8 encoding issue with WP >= 2.5
    Fix: now the widget should better integrate with your theme
    Change: Note: the way to call WPPP_show_popular_posts() to integrate the plugin in non-widget-ready themes has changed. See docs above.

License

Wordpress.com Popular Posts is released under a GPL v3 license.

If you like this plugin, then buy me a coffee!

57 comments so far

  1. Rattling the Kettle Aprile 2, 2008 7:39 pm

    I upgraded to wordpress 2.5 yesterday (and installed the WP stats plugin), and installed this plugin today. I followed all these steps, and added the widget to my sidebar. Yet it doesn’t show up! Could this be because there isn’t enough wordpress stats data for the widget to cull (less than 24 hours since upgrading the wordpress software), or is it just not compatible with wordpress 2.5?

  2. frasten Aprile 2, 2008 8:18 pm

    Hi :-)
    If you open your dashboard, under Blog Stats, then click on “Top Posts & Pages”, and summarize by “All time”, is your list empty? In this case, you should wait for wp-stats to update its logs.
    This blog is powered by Wordpress 2.5, so that shouldn’t be the cause of your issue.
    What version of Wordpress.com Stats are you running? I have v1.2, and seems to work fine.

    Also check in the widget options that the number of posts is set to a value (for me it’s 5).

  3. Rattling the Kettle Aprile 2, 2008 10:44 pm

    Thanks for the quick reply! It looks like the problem was that I was using v1.1.1 of Wordpress Stats. I switched to v1.2 and it started working immediately. Thanks again!

    What plugin do you use for allowing users to edit their comments? I love it!

  4. frasten Aprile 3, 2008 2:16 am

    Great! I’ll add the requirement of wordpress.com stats v1.2 to the FAQ. Thank you for reporting.
    The plugin to edit comments is WP AJAX Edit Comments, really useful.
    See you soon! :-)

  5. Nikna Aprile 3, 2008 12:06 pm

    Hi, is there a way of inserting “popular post” to sidebar.php without widgets enabled?

  6. frasten Aprile 3, 2008 12:28 pm

    Yes, add this code where you need:
    <?php if (class_exists('WPPP')) WPPP::init(); ?>.
    I’ll add it to the docs.

  7. frasten Aprile 3, 2008 1:23 pm

    Please ignore my previous comment.
    Grab version 0.2.2 of Wordpress.com Popular Posts, then add this code where you need:

    <?php if (function_exists('WPPP_show_popular_posts')) WPPP_show_popular_posts(); ?>

    My apologizes.

  8. Nikna Aprile 3, 2008 1:56 pm

    Wow, That was fast. Many thanks!

  9. Chris Aprile 8, 2008 10:26 pm

    Hiya - loving your work on this plugin - really handy way of helping people navigate the site.

    Is there any way I can restrict the popular posts to, say, the past week or month for example?

    Also, is there any way of excluding pages and just counting posts?

    Reckon these would make really useful additions to a great plugin.

    Chris

  10. frasten Aprile 8, 2008 10:33 pm

    Thank you for your suggestions!
    They will be added in next version.

  11. Chris Aprile 8, 2008 10:35 pm

    Nice one - thanks for the fast reply!

  12. JunkieYard Dot Com Aprile 9, 2008 5:32 am

    quote
    “Also check in the widget options that the number of posts is set to a value (for me it’s 5).”
    unquote

    How can I set the number of post if I got a themes that disable widget? any code for that? ;-) and what plugins did you used for this comment smilies… love it… :-D

  13. frasten Aprile 9, 2008 1:18 pm

    Hmmm, yeah I forgot about that.
    I’ll add new arguments in the function “WPPP_show_popular_posts”, in next version.

    The plugin for the smilies is Smilies Themer Toolbar, developed by me :-) you can find it here!

  14. JunkieYard Dot Com Aprile 9, 2008 10:45 pm

    thanks… (L) I think this popular post plugin makes my IE error loading my website… Got no prob with FireFox though…

  15. frasten Aprile 10, 2008 12:06 am

    @JunkieYard Dot Com: now in version 0.4.0 you can add arguments to the function WPPP_show_popular_posts(), download the new version and read the docs above.
    I’ll look into your error with IE.

  16. Eagle Aprile 10, 2008 10:02 am

    Hi

    very nice plugin, but is it possible for me to add number of post views in front of the list of most view posts?

  17. frasten Aprile 12, 2008 3:07 am

    Hi, added to wishlist.

  18. mahmut Aprile 12, 2008 12:31 pm

    its reaally great.. i searched very long time. i find it. thank for your work.. (L)

  19. iJohn Aprile 15, 2008 11:39 pm

    Excellent Plugin!

    I do have a suggestion tho for it. When I tried to install it on my blog, it changes the formatting for the title of the sidebar. Where it says Popular Posts it is aligned left and different text than my normal sidebar. Is there a way to change some formatting on it so it looks like the rest of my sidebar titles?

  20. frasten Aprile 16, 2008 5:18 pm

    @Eagle: implemented in v1.0
    @iJohn: it should be fixed in v1.0. Now it is formatted by the theme. Let me know if it did the trick :-)

  21. Joanne Aprile 19, 2008 12:14 am

    Thanks for this plugin. It’s working great.

    I am having some troubles with customizing the formatting to match the stylesheet of my theme. When I call the function in my sidebar.php file, are the results returned with a tag or something? I seem to have a bullet point associated with each popular post item that I can’t seem to get rid of.

    Thanks for your help,
    J.

  22. frasten Aprile 19, 2008 3:34 am

    Hi!
    Actually, every link is part of an unordered list:

    <ul class='wppp_list'>
      <li><a href='#'>My first link</a></li>
      <li><a href='#'>My second link</a></li>
      ...
    </ul>
    

    So, you must follow these steps:
    - download and install latest version, v1.0.1 (that addresses your issue)
    - add something like this to your style.css file (in your theme folder):

    ul.wppp_list li {
      list-style-type: none;
    }
    

    to remove the bullet.
    (just tried on your site, with firebug, and it does the job).
    If you know some CSS, you’ll be able to fully customize it.
    Enjoy! :-D

  23. Eagle Aprile 20, 2008 12:47 pm

    :-/ I can’t see comments?

  24. frasten Aprile 20, 2008 4:16 pm

    Huh? What kind of comments?

  25. Joanne Aprile 21, 2008 9:59 pm

    @frasten: Thanks! The information about the wppp_list class is exactly what I needed. It’s working great now - and I customized using CSS. All the best, and thanks again for the fast response.

  26. Lealcy B. Junior Aprile 23, 2008 10:52 pm

    I activated the plugin, but when I go to wp-admin/widgets.php to add the widget, I got this error:

    Fatal error: Only variables can be passed by reference in ~/public_html/wp-content/plugins/stats.php on line 548

    WordPress.org 2.5.0
    WordPress.com Stats 1.2.1

  27. frasten Aprile 24, 2008 12:22 am

    Hi, it’s a Wordpress.com Stats issue.
    However, I looked at the code, and this happens when you have a corrupted stats cache.
    To fix it you have to manually execute (via phpMyAdmin or similar) this query, in your WordPress database:

    DELETE FROM wp_options WHERE option_name = 'stats_cache'

    Next time you reload the page, the cache will be re-created and it should work as expected.

  28. Eagle Aprile 24, 2008 3:25 pm

    that time I check this page, I couldn’t see the comments, but now I have them,

    by wish list you mean, you gonna add it later, or we have now, and just need to do some configuration?

    thanks alot

  29. Lealcy B. Junior Aprile 24, 2008 5:01 pm

    frasten, after I delete stats_cache, I got the widgets.php to work, but after I added the widget to a sidebar, the error returned. I had to disable the plugin.

  30. frasten Aprile 24, 2008 6:04 pm

    @Eagle: the wishlist is a feature request list that I keep.
    However your request was implemented in v1.0.
    To put the number of post views you can customize the widget options, changing the format to something like:
    <a href='%post_permalink%' title='%post_title%'>%post_title% (%post_views%)</a>

    @Lealcy B. Junior: something must be wrong with your installation of Wordpress.com Stats.
    Your cache gets broken every time it is recreated.

    Try to contact the authors at http://andyskelton.com and/or http://blogwaffe.com.

  31. Lealcy B. Junior Aprile 24, 2008 7:26 pm

    Yes, I think so. Any directions?

  32. Eagle Aprile 25, 2008 1:14 pm

    It works, you are gr8

    thanks alotttttttttttttttttttttttttttttttttt (F)

  33. frasten Aprile 28, 2008 11:42 pm

    @Lealcy B. Junior: let’s try this:
    edit the file stats.php, in the Wordpress.com Stats Plugin folder, and change line 543:

    if ( !$stats_cache = get_option( 'stats_cache' ) )
      $stats_cache = array();

    to:

    $stats_cache = get_option( 'stats_cache' );
    if ( !$stats_cache || !is_array( $stats_cache ) )
      $stats_cache = array(); 

    and re-upload your wordpress.com stats plugin.

    This could be a workaround; however if your blog receives many visits this could use some bandwidth (if your cache doesn’t work, it makes a requests to wordpress.com servers, on each visit).

  34. Max Carvalho Aprile 29, 2008 8:34 pm

    I was with this same problem. But now it is ok. Thanks for share this excellent plugin.

  35. [...] WordPress.com Popular Posts [...]

  36. Trisha Maggio 1, 2008 4:33 am

    This is a really great plugin - thanks!

    Any idea when you might update it to be able to exclude pages? I want to show only popular posts without pages being shown also…..for example, my “Home” page always shows up… :)
    Thank you!

  37. frasten Maggio 2, 2008 2:14 am

    @Trisha, @Chris: Right now! :-D download v1.1 above.
    It’s a little hackish, but it should work fine. (B)

  38. Kes Maggio 2, 2008 2:34 am

    Nice plugin. It works great.
    This is a great option if you have WP-Cache installed and wanted functionally like WP-PostViews.

    But one thing I’m missing, is to show the views for posts by category. How can I do that ?

  39. Trisha Maggio 2, 2008 3:19 am

    YAAY! It works! I’m so happy! I’m off to pay you a donation! (L)

  40. Trisha Maggio 2, 2008 3:28 am

    frasten you should let people donate more than just the price of a cup of coffee - I wanted to send you more but it wouldn’t let me change the amount - I’ll come by in another day or so and buy you another cup!

  41. frasten Maggio 2, 2008 3:51 am

    Thank you! :-P I really appreciated your donation, I’ll keep on working on these plugins!
    And I edited the link for the donations, thank you for reporting.

  42. Chris Maggio 2, 2008 10:14 am

    Brilliant, brilliant, brilliant - well done. Exactly what I wanted. I’ll be winging you some cash on Paypal when I get five mins to sort. Top man.

  43. Andy Maggio 2, 2008 11:03 pm

    I tried to get this plugin to work but whenever I go to add it in the widget section it just dissapears after I click “Add”. I have not upgraded to wordpress 2.5.1 yet is that needed to get it to work?

  44. [...] also put a “Popular Posts” list on the sidebar. [...]

  45. frasten Maggio 3, 2008 12:28 pm

    @Andy: Hi, what version of WordPress are you using? It’s a very strange behavior. :-/

  46. Andy Maggio 3, 2008 5:12 pm

    I am using wordpress 2.5 and I have wordpress.com stats version 1.2

  47. Andy Maggio 3, 2008 5:23 pm

    I just tried it again and what seems to happen is after I click “add” popular posts widget under Available Widgets all the widgets under “Current Widgets” dissapear including the Popular posts one. They do not return unless I refresh the page and this all happens again if I try to add Popular posts every time but does not happen if I try to add other widgets. Its strange.

  48. Andy Maggio 3, 2008 5:39 pm

    Sorry for my third post in a row but I thought I would tell you the good news that I got it to work! It turns out it was a browser bug! The Popular Posts widget would not add itself to the Current Widgets in IE7 but worked fine in Firefox. So the plugin is working fine on my site now!

  49. ComicNerd.com Maggio 6, 2008 4:45 am

    Hello,

    I have the most recent version of both this plugin and the stats plugin and everything seems to be setup correctly.

    Unfortunately, no matter what nothing populates :(

    When I add the widget it just lists the title but doesn’t list naything else - could it be my theme?

    Any ideas? Thanks!

  50. ComicNerd.com Maggio 6, 2008 4:53 am

    Actually, this just now popped up in the place of popular posts:

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near — it won’t let me post the code error here…

    Pretty weird, huh? Any suggestions? Thanks!

  51. frasten Maggio 6, 2008 1:06 pm

    @Andy: Thank you for reporting. Actually, the widget configuration under IE7 looks really crappy.
    I’ll look into that.

    @ComicNerd.com: I’ve PMed you, I need the complete MySQL error.

  52. Steker Maggio 10, 2008 12:53 am

    hi, thank you for this great plugin, im wondering, is it possible to make some popular lists using categories with this plugin ?

  53. Marcelo Maggio 13, 2008 11:12 pm

    Hi,

    I was getting the same fatal error described by Lealcy B. Junior. The solution you supplied him works for me as well.

    But I’d like to suggest you to work on a general fix. My WordPress (2.5.1) and your plugin (1.1.1) should work fine in all cases.

    BTW your plugin is a nicely done job. Gongratulations. ;-)

  54. frasten Maggio 14, 2008 12:19 am

    @Steker:
    Can you please elaborate on the feature you requested?

    @Marcelo:
    I’ve contacted the WordPress Stats authors, but I haven’t received any answers.
    So, like you suggested, I’ve included in v1.1.2 a temporary fix for that error. 8-)

  55. Marcelo Maggio 14, 2008 12:23 am

    Great!

    Does it mean I can undo the changes on stats.php?

  56. frasten Maggio 14, 2008 12:26 am

    @Marcelo:
    Yes. Actually, the fix in v1.1.2 is the same as what you changed in stats.php.
    It doesn’t harm, but you can safely remove the fix, because it is already included in Wordpress.com Popular Posts.

  57. frasten Maggio 14, 2008 11:12 am

    @Marcelo:
    The authors of Wordpress.com Stats will include the fix in the next version of Wordpress.com Stats, as you can read in the development branch log.

Leave a comment

Please be polite and on topic. Your e-mail will never be published.

:o) :-D :-( ;-) :-P =-O 8-) :-/ O:-) :-! >:o C:-) :-(|) O-) :@ :-[ (B) (^) (P) (@) (O) (D) :-S ;-( (C) (&amp;) :-$ (E) (~) :-* (I) (L) (8) (T) (G) (F) (*) (N) (Y) (U) (W)