The MU forums have moved to

Releasing my stats setup (37 posts)

  1. zappoman
    Posted 17 years ago #

    Back on topic...

    I've been haunted by Dr. Mike's idea of wanting to limit top posts to 1 per blog... in other words if a blog is very popular and they have multiple posts that are in the top posts, you might not want to show more than 1 of their posts in the list.

    Anyway, I knew there had to be a way to do this with just a sql tweak to my plugin, so while I was debugging something else tonight, I let my brain wander back to this question, and I finally came up with the right SQL to do the trick.

    If you want to do this, try adding a function to my top posts plugin that uses the following SQL...

    SELECT blog_id,post_id,MAX(post_hits) as 'max_post_hits'
    (SELECT blog_id, post_id, COUNT(post_id) AS 'post_hits'
        FROM wp_blogs_zap_hits
        WHERE post_id <> 0
        GROUP BY blog_id, post_id
        ORDER BY post_hits DESC) as top_posts
    GROUP BY blog_id ORDER by max_post_hits DESC;

    The trick here is that you're essentially using the normal query that's in the code already as a subquery for another query that pulls out the max post_hits.

    If this makes sense to you then go for it...

    Otherwise I do plan to make a release of the top posts plugin soon that adds this feature as well as adds the top_blogs code suggested by ezequielc and fixes a caching bug found by Nis (and confirmed by me as it was messing up my dashboard on one of my blogs).

    follow me?

  2. zappoman
    Posted 17 years ago #

    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.

    More details here...

  3. enseignement
    Posted 17 years ago #


    Is the stats plugin released ? How is it going for you drmike ?

  4. suleiman
    Posted 17 years ago #

    awesome work zappo! :)

  5. newspartner
    Posted 17 years ago #

    thanks man very nice Working Now...

  6. Houston Web Designer
    Posted 15 years ago #

    I know this thread is old, but most of the main players are still active in the forums. I like the idea of top blogs, but I'm looking for a featured blog plugin, to where I can designate certain blogs to populate.

    I'm working on a free profile site, but there are perks to being a featured of which is being listed on the home page...

    Any ideas?

  7. dsader
    Posted 15 years ago #

About this Topic