Popularity Contest Hacked

Posted on March 1, 2007
Filed Under weblogs | 17 Comments

I made myself a little hack of the Popularity Contest WordPress plugin. I was really sick of seeing that stupid “Rosie V. Trump” post at the top of the list for the last 3 months, so I added in a function that shows the most popular posts in the last 30 days. I suppose even better would be to make that parameterized so that you could call it with any number and have it look back that many days. It’s worth noting that this sort of thing already exists in the management pages, but I had to hack it to expose it to the public side. Maybe I’ll do that and then submit it back to Alex King to include it in the main release. Although, it took me 3 minutes to do it while unfamiliar with the code so I’m sure he could do it in 45 seconds.

Update: I tried to post the thing in coments and it styled it and it sucks. Here is a zip file of my hacked version. Replace your popularity-contest.php with the one from the zip file and then you’ll have a new function you can use in your template called akpc_most_popular_in_last_month() . Have at it, friends.

Related Posts:
  • Popularity Contest It Is
  • WordPress Plugins for XMas
  • Popularity Contest: WordPress Plugin Hall of Shame
  • iPodderX Name Change
  • Win a Daisy Open Source MP3 Player Kit
  • Comments

    There is a posted comment policy for this blog. Please respect the rules.

    17 Responses to “Popularity Contest Hacked”

      Comment Permalink
    1. tiltededge on March 3rd, 2007 11:54 am

      I predict the next most popular thread will be on talking urinal cakes.

    2. Comment Permalink
    3. Leo Maia on March 12th, 2007 10:18 pm

      Please tell me: how did you do it?

      I’ve been trying to the exact same thing for me. I can’t stand seeing my top post for the last 3 months every single day.

      Thank you in advance!

    4. Comment Permalink
    5. dave on March 12th, 2007 10:36 pm

      Add these to your popularity-contest.php

      Right before the end of the class, put this:

      function show_top_ranked_in_last_month($limit, $before, $after) {
      global $wpdb;
      $temp = $wpdb;

      $join = apply_filters('posts_join', '');
      $where = apply_filters('posts_where', '');
      $groupby = apply_filters('posts_groupby', '');
      if (!empty($groupby)) { $groupby = ' GROUP BY '.$groupby; }

      $posts = $wpdb->get_results("
      SELECT ID, post_title
      FROM $wpdb->posts
      LEFT JOIN $wpdb->ak_popularity pop
      ON $wpdb->posts.ID = pop.post_id
      $join
      WHERE post_date > (SUBDATE(CURDATE(), INTERVAL '30' DAY))
      AND post_status = 'publish'
      AND post_date < NOW()
      $where
      $groupby
      ORDER BY pop.total DESC
      LIMIT ".intval($limit)
      );
      if ($posts) {
      foreach ($posts as $post) {
      print(
      $before.'ID).'">'
      .$post->post_title.''.$after
      );
      }
      }
      else {
      print($before.'(none)'.$after);
      }
      $wpdb = $temp;
      }
      Somewhere towards the bottom with the similar functions, add this:


      function akpc_most_popular_in_last_month($limit = 10, $before = '

    6. ', $after = '
    7. ') {
      global $akpc;
      $akpc->show_top_ranked_in_last_month($limit, $before, $after);
      }

    Comment Permalink
  • WordPress Wednesday News: WordCamp Filling Up Fast, WordPress 2.2.1 Mandatory Upgrade, Hot WordPress Themes and Plugins, WordPress Security, and WordPress Nerds Blog Naked : The Blog Herald on July 4th, 2007 7:36 pm

    [...] Popularity Contest WordPress Plugin Hacked to Feature Most Popular in 30 Days: Evil Genius Chronicles offers a hacked version of Alex King’s Popularity Contest WordPress Plugin. The original Plugin lists the most popular posts on your blog. The hack changes the number to the most popular posts within the last 30 days. I’d love to see one that mixed this in with some algorithm that also included your overall most popular posts, mixing things up and giving your readers more variety to choose from. [...]

  • Comment Permalink
  • buzzdroid on July 7th, 2007 8:06 pm

    Interestingly, we implemented your hack thinking this would show the post popularity according to the last 30 days (or 7 days, 10 days or whatever you choose to use as the interval). That is not what the hack does. This hack acts as a filter of sorts on what posts are shown in the list – the hack shows the popularity of the posts with a post date within the time period chosen.

    This might be confusing to some people who try to implement the hack. The hack works great to filter the post in the list and show only posts from the time period, but it does not show all posts according to their popularity figures accumulated during the time period.

    If you can do that, that would be kick ass.

  • Comment Permalink
  • dave on July 9th, 2007 8:06 pm

    buzzdroid,
    You can’t do that with the plugin as it exists. It doesn’t keep individual hit information, just totals so the information you want to use isn’t there.

  • Comment Permalink
  • ales on July 24th, 2007 5:56 am

    ok, now how would I do this for 7 days instead of 30.

  • Comment Permalink
  • ales on July 24th, 2007 5:58 am

    duh.. ok, probably change query from (SUBDATE(CURDATE(), INTERVAL ’30′ DAY)) to (SUBDATE(CURDATE(), INTERVAL ’7′ DAY))

  • Comment Permalink
  • Maski on August 22nd, 2007 12:18 am

    After a little code fighting i finally got it working… thanks

  • Comment Permalink
  • Scott on September 2nd, 2007 10:45 am

    Big dummy that I am, I can’t figure out what the proper code for this hack actually is. Is there a version with no styling available somewhere?

  • Comment Permalink
  • Ash Haque on December 28th, 2007 4:18 pm

    Exactly what I’ve been looking for! Big thanks

  • Comment Permalink
  • snowcrash on February 28th, 2008 10:05 am

    Hi

    Will your hack work for WP 2.3.3?
    As the original plugin has been upadated on Alex King’s page

    thanks

  • Comment Permalink
  • Vince on June 29th, 2008 4:30 pm

    Just tried it on my website, http://offmanhattan.com

    Your zip file isn’t downloading so i had to go from what you had in the comments and it failed.

    Any way you could get the zip file up again please?

    Thanks!

  • Comment Permalink
  • dave on July 2nd, 2008 6:39 pm

    Vince, I fixed the downloading problem and you can get it again. Thanks for pointing out the problem.

  • Comment Permalink
  • Popular Posts Are BACK! | Going to Seminary on September 1st, 2008 8:22 pm

    [...] posts from the last 30 days.  For those interested in knowing what I did… well, I use this hack to get this plugin to query only the last 30 days, then I follow the instruciton here to get it to [...]

  • Comment Permalink
  • El blog de Gabriel » Popularity Contest para wordpress 2.6.2 on September 20th, 2008 3:37 am

    [...] También he añadido una mejora con el listado de los más populares del último mes [...]

  • Comment Permalink
  • Popularity Contest 1.4 Wordpress 2.6 Plugin Fixed and Hacked | ...::: Guatewireless.org ::::.. on September 24th, 2008 4:48 pm

    [...] akpc_most_popular_in_last_month() hack to show the most popular post from the las 30 [...]

  • Leave a Reply