Subscribe via

Make Popularity Contest Work with WP-Super-Cache

Previously I wrote ‘Make Your WordPress 10X faster During Traffic Storms‘, which is a post about automatically turning WP-[Super]-Cache on/off and automatically switching your WordPress theme to a lighter theme during heavy traffic. One of the main reasons that I had this setup was because I could not get statistics to work with WP-Super-Cache (i.e. my chCounter & Popularity Contest plugin is hosed).

After some tinkering, I was able to get chCounter and Popularity Contest to work with WP-Super-Cache. This involves using javascript to count instead of PHP. chCounter was a simple change, but Popularity Contest was a bit more challenging. Usually I would immediately post the “How-to” here, or rather release the modded plugin to the public myself, but I believe that I shouldn’t step on Alex King’s shoes (the original developer of Popularity Contest). I’ve sent the Popularity Contest code to Alex for code review. He’s been doing some of the same work, and hopefully he can incorporate some of my changes into the plugin and release it to the public soon.

If anybody would like to use my version of the Popularity Contest before Alex King releases it to the public, you may download the WordPress 2.3.3 and WordPress 2.5 compatible version here:

Download: Popularity Contest JS Mod for WordPress 2.3.3.
*Note*
– This method does not work with feed_views (since you can’t really inject javascript into XML feeds and get them to reliably execute), but this mod takes care of home_views, category_views, archive_views, and single_views (from what I understand: comments, pingbacks, trackbacks are always working).
– Plugin is tested only up until WordPress 2.3.3 (tested not working on WordPress 2.5, see below for version 2.5).

*Special WordPress 2.3.3 Install Instructions*
Intallation works the same way as the original Popularity Contest except that you will need to do ONE OF THE FOLLOWING:
1. Place a symbolic link from plugins/popularity-contest-js.php -> plugins/popularity-contest/popularity-contest-js.php
2. Move popularity-contest-js.php directly under your plugins/ directory

Download: Popularity Contest JS Mod for WordPress 2.5.
*Note*
– This method does not work with feed_views (since you can’t really inject javascript into XML feeds and get them to reliably execute), but this mod takes care of home_views, category_views, archive_views, and single_views (from what I understand: comments, pingbacks, trackbacks are always working).
– Plugin only works with WordPress 2.5 and is not backwards compatible with WordPress 2.3.3.

*Special WordPress 2.5 Install Instructions*
Intallation works the same way as the original Popularity Contest except that you will need to do ONE OF THE FOLLOWING:
1. Place a symbolic link from wp-content/popularity-contest-js.php -> plugins/popularity-contest/popularity-contest-js.php
2. Move popularity-contest-js.php directly under your wp-content/ directory

That should be all. I would really appreciate it if you can provide any feedback (security issues, better implementations, or other important thing that I’m totally not aware of). Also please feel free to post questions and keep me posted on how things are going with the plugin.

40 Responses to “Make Popularity Contest Work with WP-Super-Cache”

[go to last comment]
  1. Thaya Kareeson

    Just found out that this post is being Stumbled Upon courtesy of Donncha O Caoimh’s submission to stumbleupon.com! Thank you!

    For those of you who end up trying out my modded Popularity Contest. Please please please log any bugs, questions, comments, and ideas on this comment thread.

  2. JTPratt’s Blogging Mistakes

    Wow – could you do this exact same mod for Lester Chan’s PostViews? That’s pretty much the only reason I can’t use cache or supercache, because it screws up all the counts.

  3. Thaya Kareeson

    @JTPratt
    I might be able to do that. I will look into it. I’ll keep you posted.

  4. Make WP-PostViews Work with WP-Super-Cache | OMNINOGGIN

    […] plugin_version:”2.0″} ; In response to JPratt’s comment on my post, “Make Popularity Contest Work with WP-Super-Cache,” I am releasing a modification of Lester Chan’s WP-PostViews plugin to support […]

  5. Thaya Kareeson

    @JTPratt
    Fresh out of the oven: Make WP-PostViews Work with WP-Super-Cache. Let me know how it works out for you. Please remember to write about it if you like it! 🙂

  6. Balaji Dutt

    #1 Result for wp super cache popularity contest on Google 🙂

    I’m currently running WP 2.5.1 and am planning to upgrade to WP 2.6. Have you tried your plugin in WP 2.6? Is it safe to upgrade using this version?

  7. Thaya Kareeson

    @Balaji Dutt
    Thank you for visiting! I’m running WP 2.6 right now and the plugin seems to work fine. 🙂 I’m planning to release my own version of Popularity Contest pretty soon, so you wouldn’t have to worry when WP goes to 2.7. Please stay tuned!

  8. Balaji Dutt

    @Thaya – that is great to hear! Please keep us posted on your fork of Popularity Contest – it’s a great plugin, but the lack of development on Alex’s side is a bit frustrating.

    One last question – I have a Windows based environment I would like to install the plugin on and test with WP 2.6 before updating my site. Is that symbolic link vital for the plugin to work – because symlinks are possible in Windows, but can have unpredictable results.

  9. Thaya Kareeson

    @Balaji Dutt
    Symbolic links are not required. You can just move popularity-contest-js.php to under your wp-content/ directory.

  10. Lino

    hello,
    thanks for your work with this plugin. i desire install it. i have see, when i install your plugin my wordpress report me a new version of wp-postviews 1.31.
    I have move your popularity-contest-js.php in my wp-content/ directory.

    My questions is: Can i upgrade in automatic this plugin from plugin pannel in wordpress?

    thanks for all and excuse me for my english.

  11. Thaya Kareeson

    @Lino
    Thank you for visiting. Are yout talking about wp-postviews or popularity contest? With popularity contest, I don’t think you can use the “upgrade automatically” feature with this mod because the modifications will just get overwritten.

    That being said, please stay tuned. I’m planning to release my own version of Popularity Contest soon with more features to chew on ;). You can subscribe to the RSS feed to stay posted.

  12. Blog Tips for Beginners

    hey Thaya,

    Firstly, thanks for the add on BC. Secondly, I’ll like to know if your version of Popularity Contest works on WP 2.6. I read your comment that it worked fine for you but it didn’t seem to work for me so I’m thinking of the possibility of using your version. This is the one of the 2 plugins that fail to work on my blog, the other being SezWho.

    Yan

  13. Thaya Kareeson

    @Yan
    Thank you for visiting. I’m using my own modded version of Popularity Contest (the one I packaged for WP 2.5). It works fine with WP 2.6 as long as you do not move your wp-content folder. SezWho did not fail on me either. Do you have the latest version installed?

  14. Blog Tips for Beginners

    Yeah, for some weird reasons, I couldn’t get the the popup to work when you hover the ‘Check me out’. I believe I did install the latest one.

    Anyway, I’ll give your version of PC a try and I’ll keep you updated.

    Thanks. Thaya.

    Yan

  15. Blog Tips for Beginners

    Nope, it doesn’t work for me either.

    “Plugin could not be activated because it triggered a fatal error.”

    Same old story…

    Yan

  16. Thaya Kareeson

    @Yan
    That’s interesting. Let me email you to see what issues you are having. It’ll be easier to debug that way.

  17. LastOne

    Hi Thaya, just found you via google. You mentionted that it was simple to geht wp super cache working with chcounter. I have the same problem but i do not know how to fix this problem. How did you solve the problem exactly? Woud be great if you could help.

    Greetz,
    Sebastian

  18. Thaya Kareeson

    @Sabastian
    Thank you for visiting and sorry for the late response (I’ve been on a bit of a vacation).

    What you need to do is have chCounter count via Javascript instead of via PHP. For example, you should write something like this to your footer:

    <script type="text/javascript">
    // <![CDATA[
    cstatus = "active";
    visible = "0";
    page_title = "";
    url_of_counter_file = "http://chCounter.omninoggin.com/counter.php";
    page_url = unescape( location.href );
    referrer = ( document.referrer ) ? document.referrer : "";
    page_title = ( page_title.length == 0 ) ? document.title : page_title;
    document.write( "<script type=\"text/javascript\" src=\"" );
    document.write( url_of_counter_file + "?chCounter_mode=js&amp;jscode_version=3.1.3&amp;status=" + cstatus + "&amp;visible=" + visible + "&amp;page_title=" + encodeURIComponent( page_title ) );
    document.write( "&amp;page_url=" + encodeURIComponent( page_url ) + "&amp;referrer=" + encodeURIComponent( referrer ) + "&amp;res_width=" + screen.width + "&amp;res_height=" + screen.height + "\"><" + "/script>" );
    // ]]>
    </script>
    <noscript>
    <object data="http://chCounter.omninoggin.com/counter.php?chCounter_mode=noscript" type="text/html"></object>
    </noscript>

    Ugly isn’t it? You’re probably better off by just viewing this page’s source and grabbing the code from my site’s footer.

  19. ZimTimes

    Hi

    I managed to install the modified popularity contest onto our site running WordPress 2.6.1. It did not appear that the plugin was updating the counts for the posts to reflect their popularity, so I came back here again. Am I to understand it correctly that I need to copy and paste the code above, into my footer, in order to have the site use javascript and not php for the counts? Have already installed the code, but want to make sure.

  20. LastOne

    Thx Thaya, this helps a lot. Hope you had a great vacation. 😉 I’m just spendig three weeks of vacation at home.

  21. Thaya Kareeson

    @LastOne,
    No problem. I’m sure you remembered to change the omninoggin.com URL in the javascript to your own counter URL.

    I had a wonderful vacation with lots of outdoors activities. It’s good to get out once in a while.

  22. LastOne

    Yes, i changed the URL 😉

    How about Visitors without Java? I guess thex aren’t count with chcounter then? What does the “noscript” part exactly do?

  23. Thaya Kareeson

    @LastOne
    I just looked at the chCounter source code to figure this out. It’s quite clever actually. The “noscript” part will execute when the visitor doesn’t have javascript enabled. When this happens, the browser will try to access the “counter.php?mode=noscript” version of chCounter, which just counts the visitor with minimal information logged. Things like referrer URL, search phrase, etc are not logged since you do not have access to it via javascript variables.

  24. ZimTimes

    Do I need to install chCounter on my site for the above script to make popularity contest work? I am confused! If yes, where do I get chCounter?

  25. Thaya Kareeson

    ZimTimes
    As I said before, you do not need chCounter to get Popularity Contest to work.

  26. ZimTimes

    Well, I cannot figure out the reason why, but my Popularity Contest is only counting comments, and pings, but seemingly nothing else. I have removed the above quoted javascript from my footer. Should I leave it on there/ This all is confusing me now.

  27. Thaya Kareeson

    @ZimTimes
    You do not need to add the above quoted javascript to your footer. Please leave it out.

    I just went to your site, enabled firebug and inspect the section of your site that’s supposed to call the javascript and count the visitor in popularity contest and I see:

    Warning: main(plugins/popularity-contest/popularity-contest.php) [function.main]: failed to open stream: No such file or directory in /home/thezi0/public_html/wp-content/popularity-contest-js.php on line 3

    Warning: main(plugins/popularity-contest/popularity-contest.php) [function.main]: failed to open stream: No such file or directory in /home/thezi0/public_html/wp-content/popularity-contest-js.php on line 3

    Fatal error: main() [function.require]: Failed opening required ‘plugins/popularity-contest/popularity-contest.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/thezi0/public_html/wp-content/popularity-contest-js.php on line 3

    Did you follow instructions and

    Move popularity-contest-js.php directly under your wp-content/ directory?

  28. ZimTimes

    Aye, thanks for taking the time to do this. Trust me, I am feeling really dub right now, but do need this to work. The js.php file is actually directly under the wp-content/ folder, and is not locate in any subfolder there. The only thing I see from the firebug report above is that my popularity-contest.php file is directly under the plugins/ folder, and not within a subfolder like so plugins/pupularity-contest/popularity-contest.php I think when I tried to do it this way before, the plugin was not recognized by the wordpress dashboard. Should I do this?

  29. ZimTimes

    Ok, I think I found the issue. The popularity-contest-js.php has a require plugins/popularity-contest/popularity-contest.php line in it. I have changed this now to plugins/popularity-contest.php THis should fix it, shouldn’t it?

  30. Thaya Kareeson

    O, I see, you have an irregular plugins structure. Is there a reason for that? It would’ve been easier for you to just place all contents of the zip file under under plugins/popularity-contest/* and move poplarity-contentest-js.php to your wp-content/ directory. That way the plugin will get recognized by the dashboard too.

  31. LastOne

    Thaya i just tested your code against the php-version. I made 2 installs, 2 databases. chcounter (PHP) and chcounter2 (JAVA):

    The Stats are very Different:

    Visitors tody: 87/30
    Page Views today: 401/46

    Do you have any idea why php counts so much more?

  32. Thaya Kareeson

    LastOne
    What do you mean by 87/30 and 401/46? Do you mean pageviews/unique visitors?

  33. LastOne

    87 were count by php-version
    30 by java-version

    same goes for the other figures

  34. Thaya Kareeson

    @LastOne
    I’m not sure why the numbers are different from just the data that you give me. Have you looked into the online log for both chcount and chcount2 and see if you can figure out what kind of visitors did not get counted?

  35. LastOne

    Yes, i just copied the database and only changed url and database name … so all settings must be the same

  36. Thaya Kareeson

    @LastOne
    I’m asking if you can look at the visitor logs to see what type visitors got recorded with PHP counting vs. JS counting. You can do so by logging into your chCounter admin and clicking on the “Log data” page.

  37. Chaos Inc.

    Hi there Thaya,

    Awesome thing you have done!!! However, I am actually using Hyper Cache by Satollo which is much easier to implement I guess. I tried using this plugin but it didnt work for me.

    After downloading the content of 2.5 (I am using 2.6.3) I noticed that you have a sidebar.php within the archived folder. Do I need to upload that by overwriting the default sidebar.php of my theme (am using Gazette by Woo)?

    I am trying this again and I really hope that you will help me with this if it does not work out for some reason. Thanks in advance!

  38. Thaya Kareeson

    @Chaos Inc.
    Wow I totally lost track of this comment for months! Sorry about that!

    I don't think you need to modify the sidebar.php file at all. This implementation has nothing to do with sidebar.php.

  39. Upgraded to WordPress 2.6 « OMNINOGGIN

    […] plugin was never 2.5 compatible so I assume that it would not be working for 2.6. Please see this post to download my working Popularity Contest […]

  40. Ways to Increase Visitor Activity on Your Blog « OMNINOGGIN

    […] section in your sidebar where readers can easily find more interesting posts to read.  I use Popularity Contest to do […]

[go to first comment]

Leave a Reply