Hefta-Gaub Development Blog

May 26, 2007

Latest wpmu-topposts plugin

Filed under: development, sql, Wordpress plugins, WordpressMU — zappoman @ 10:14 am

Version 0.42.4 of wpmu-topposts plugin now available…

Lots of changes:

  • Added support for top_blogs(), same calling convention as top_posts() but returns
    top blogs based on total hits to the blog for all posts on the blog.
  • Added a couple new arguments to top_posts() include a new max_per_blog which if set
    to 1 will limit the posts to 1 per blog.
  • Added days_back argument which will limit the stats to a certain number of days
    into the past.
  • Added many new formatting arguments to make it easyer to use the get_*_html functions
    and get the formating you want.
  • Fixed a couple bugs that would cause cache corruption (removed a call to
    update_post_caches() which was definitley corrupting the post cache)
  • Also correctly call switch_to_blog() in the get_*_html functions so that the
    blog template tags actually work properly.

Definitely my favorite new feature is the max_per_blog since it uses cool nested queries in SQL. yummy!

Here are some usage examples:

This will give you top posts in an ORDERED list, with hits included surrounded by square brackets.


This will give you top blogs in an UNORDERED list, without hits included.


As always, get the latest code here



  1. how do you increase the number of top post to be viewed can’t seem find where to edit it.

    Comment by Ramil Saavedra — May 28, 2007 @ 1:07 am

  2. The *top_posts*() functions support a “numerposts” parameter, and the *top_blogs*() functions support the “numberblogs” parameter.

    These parameters control the number of posts of blogs returned.

    Comment by zappoman — May 28, 2007 @ 2:15 am

  3. Installed you plugin seems to be working listing 4 posts. however I get this error on screen #

    WordPress database error: [Table ‘psych_mysoberlife.wp_10_posts’ doesn’t exist]
    SELECT *,’3′ AS ‘post_hits’,’10’ AS ‘blog_id’ FROM wp_10_posts WHERE ID = 1

    Is that cause my system does not have 10 posts? Sorry for the newbie question but thats what I am;-)

    Comment by matt — June 9, 2007 @ 3:35 am

  4. Matt,

    No, that error means that it’s trying to read the posts from a blog #10 that appears to no longer be available. Did you perhaps have a blog that you deleted? Maybe while you were testing?

    I can imagine this error happening in that case.

    I am going to release a new version of the top posts plugin soon that has a bunch of new features… including recent posts, recent comments, caching, and best of all it’s widgetize…

    I will fix this bug in this release.

    So you can wait a couple days and get the new release… OR if you want to work around the problem and you indeed did delete a blog like I suspect… then you could do the following SQL comment to clean up your table…

    DELETE FROM wp_blogs_zap_hits WHERE blog_id = 10;

    That will delete all the rows from your hits table that reference blog 10.

    Comment by zappoman — June 9, 2007 @ 5:24 am

  5. Thanks!

    Comment by matt — June 9, 2007 @ 7:26 am

  6. “Unique hits” would also be a great feature for the next version…

    I found a simple unique hits counter solution here: http://marek.litomisky.com/2006/11/26/php-simple-unique-its-counter-re-vamp/
    ,but had little luck implementing it to your plugin.

    Comment by henry — June 9, 2007 @ 4:52 pm

  7. Henry,

    That’s a great idea… I may add that in the future.. but I don’t think I’ll get it into this release. I am behind schedule and will be very busy this weekend trying to get a new release of my main site out.

    I’ll add this idea to the feature list.

    Comment by zappoman — June 9, 2007 @ 6:31 pm

  8. Zappo,

    Went in and DELETE FROM wp_blogs_zap_hits WHERE blog_id = 10;

    I think i did it right deleted blog id=10 from the blog id list. Didn’t fix the problem. Guess I’ll have to wait till the update comes out.

    Comment by matt — June 11, 2007 @ 9:20 pm

  9. thanks man very nice Working Now…

    Comment by toptech — June 20, 2007 @ 7:33 pm

  10. Thank you for good job. It’s realy great plugin.
    And I have two questions:
    1. How to exclude main blog from top_blogs?
    2. How to exclude hits, when surfer visit from rating list (now if I click to link at top_posts or top_blogs it take +1 hit)?

    Comment by mvkozyrev — January 5, 2008 @ 10:07 pm

  11. Ok. First question is down 🙂

    245. if (
    246. is_admin() ||
    247. is_404() ||
    248. is_preview() ||
    249. strstr($_SERVER[‘PHP_SELF’], ‘wp-login.php’) ||
    250. //Check is not main blog (also we can exclude blogs by id)
    251. $blog_id == 0 || $blog_id == 1
    252. //Checked
    253. )

    Comment by mvkozyrev — January 5, 2008 @ 11:11 pm

  12. How to place Avatar on wpmu-topposts plugin ?
    ….I used Avatars plugin’s Andrew (http://premium.wpmudev.org/project/Avatars)

    Comment by Playman — March 2, 2008 @ 7:25 pm

  13. Hey there zappo buddy. 🙂

    this still work good?
    Also, out of respect for the CC license, using it on a client’s site would totally fall under commercial use, yes? 😀

    I’m trying to think if I have any unreleased goodies to trade… but if it does what I want, I’d like permission to use.

    Comment by Andrea — April 30, 2008 @ 10:52 pm

  14. thanks for the plugin 😉

    Comment by saq — May 4, 2008 @ 12:30 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: