Hefta-Gaub Development Blog

April 6, 2007

Update to WPMU- Top Posts Plugin

Filed under: development, Wordpress plugins, WordpressMU — zappoman @ 12:51 am

Note, I’ve updated the code to 0.42.1 with the following changes…

  • Small bug fix to ‘maybe_create_table’ behavior. Namely, we used to try to load it if this function wasn’t available, and now we simply check that the function is available.
  • Added blog_id to the posts returned by get_top_posts. This can be useful in forming correct permalinks to your blog posts.
  • Added function zap_setup_post_globals() which in some cases will setup the globals for other wordpressmu templates to work, but this doesn’t always reliably work

You can get the latest code here.



  1. It would be nice if you could make the following:
    1. get post of a munite (or hour – don’t really matter, but “top post of an hour” will be useful on less popular services)
    2. get list of top blogs for today;
    3. don’t count hits of blog owner(s);
    4. and the most important – maybe it should count hosts, not hits? like IP or something. Just INSERT user’s IP, and when function “get_top_posts” is called use “select …. DISTINCT (viewer_IP)” to order posts by. Otherwise anyone with nice internet connection will be able to bump his posts\blogs To The Top

    And, of course, thank you for your work! Appreciate it!

    Comment by b3atb0x — April 28, 2007 @ 2:12 am

  2. I get this error:

    WordPress database error: [Table ‘wpmu.wp_blogs_zap_hits’ doesn’t exist]
    INSERT INTO wp_blogs_zap_hits (blog_id,post_id,hit_time) VALUES (‘2′,’0’,1178249929)

    Apparently the table isn’t being created properly.

    Comment by suleiman — May 4, 2007 @ 3:47 am

  3. so….what are you expecting we should put in the database in terms of tables and columns? it looks pretty cool, but a couple comments on usage either in the plugin or attached would be even better.

    Comment by th — May 4, 2007 @ 5:26 am

  4. suleiman & th:

    I’ve just released a patch (0.42.3) that should address the problems you were seeing.

    An explanation of the change is as follows: In the original version of the code I was using the wpmu function “maybe_create_table()” but that was causing problems as reported by Nis Jorgensen… so I had changed the code to only call the function if it existed. But in your case, that meant the tables weren’t getting created.

    I didn’t notice this problem because I didn’t test it in a clean install. Sorry… As I said, this is only intended as example code. 😉

    Anyway, I think I’ve fixed it now to work on clean installs (at least it worked for me when I tried it on a clean install).

    The solution was to use my own implementation (copy) of maybe_create_table(), which we can be certain is available when we need it.

    Comment by zappoman — May 4, 2007 @ 6:23 am

  5. The new version works, from what I can see. Just to be sure, what would be the code we would use to call the top ten blogs?

    Comment by suleiman — May 4, 2007 @ 7:35 pm

  6. EDIT: cancel that. I just saw that this is the top ten POSTS plugin. Though I suppose it would be easy enough to organize them by blog_id and get the top ten blogs.

    Comment by suleiman — May 4, 2007 @ 7:48 pm

  7. Hi, I’m a beginner with php so i’d like to know if/how it’s possible to fetch the whole content of a “top post” rather than just the title.

    Comment by henry — May 9, 2007 @ 11:59 am

  8. Okay, I guess I solved the problem: “echo $post->post_content;” 🙂

    Comment by henry — May 10, 2007 @ 4:27 pm

  9. Henry, Glad to see you got it figured out… sorry I didn’t reply sooner, I’ve been pretty busy the last couple days. Good luck!

    Comment by zappoman — May 10, 2007 @ 4:57 pm

  10. check out this one……

    Keep up the g00d work man!…

    Trackback by Andrea Schamoz — June 30, 2009 @ 8:58 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 )

Google+ photo

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

Twitter picture

You are commenting using your Twitter 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: