Make WP-PostViews Work with WP-Super-Cache

Thaya Kareeson
Popularity: 81%
Updated: Jul 10, 2008

In response to JTPratt’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 counting using Javascript. Please try it out to see if this works for you.

A side note to Lester Chan and Richer Yang (WP-PostViews and WP-PostViews Plus authors repectively). Please feel free to contact me about incorporating these changes into WP-PostViews and/or WP-PostViews Plus so that it can be officially committed to the wp-plugins.org repository. I would create my own version of WP-PostViews in the repository, but do not want to steal your thunder :).

Download:
WP-PostViews JS Mod for WordPress 2.5

Note:
Modded Plugin only tested to work with WordPress 2.5 and is probably not backwards compatible with WordPress 2.3.3 or earlier versions.

Special Installation Instructions:
Intallation works the same way as the original WP-PostViews except that you will need to do ONE OF THE FOLLOWING:

  1. Place a symbolic link from wp-content/wp-postviews-js.php -> plugins/wp-postviews/wp-postviews-js.php
  2. Move wp-postviews-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 email me with questions and keep me posted on how things are going with the plugin.

Rate this:
3.5 (-1 people)

30 Responses to “Make WP-PostViews Work with WP-Super-Cache”

  1. Thanks a lot.

  2. @Rosyidi
    You’re welcome! Please feel free to send me any questions or comments about this modification. And if you really like it, please write about it :-).

  3. I stil don’t understand abut “Place a symbolic link”. What is symbolic means?
    Maybe I’ll repost this plugin on May 3.

  4. @Rosyidi

    You can find information about what symbolic links are at Wikipedia. Symbolic links are only available on a Unix/Linux environment. If you are hosting from a Windows machine, you can just move wp-postviews-js.php directly under your wp-content/ directory to achieve the same effect. Hope this helps.

  5. I thank you for this fix - it worked GREAT on one of my sites! It didn’t (and may never) on my main site though, since I use 4 dozen odd plugins. I wonder, sezwho was one problem I had, as well as wp-postratings by lester chan.

    What happens with the WP-Stats plugin (wordpress.com official stats) when wp-super-cache is enabled? Are views of cached pages counted in your stats, or not?

  6. It works. And it works GREAT!
    Moving wp-postviews-js.php into wp-content was enough, no need to mess with symbolic links, for who doesn’t know how to do this ;)

  7. @JTPratt

    What is your main site? I’m not sure why it’s not working on your main site, but I believe the reason could be that the Javascript in this mod clashes with one of your other plugins’ Javascript. The mod I did here is supposed to work with any other cache plugin, but WP-Super-Cache is supposed to have a hook called “add_cacheaction” that can be used to add a count action. I’ll look into it to see if this method would work (and probably write a post about it if it does).

    @justfrank

    Thank you for visiting! I’m glad that the mod worked out for you.

  8. @JTPratt

    I forgot to answer the second part of your question. I’m pretty sure the WP-Stats plugin will not record hits if WP-Super-Cache is enabled. That said, I think it can also benefit from the method of using WP-Super-Cache’s add_cacheaction hook. I’ll explore this further and keep you posted on my findings.

  9. My main site is http://www.jtpratt. Now, after 24 hours - my other site I thought everything was working on isn’t registering and counts on postviews at all. On the other hand, WP-Stats seems to be working fine ( so far )…

  10. @JTPratt

    Interesting, I will have to look into WP-Stats to see how it works. Thank you.

  11. I can’t seem to make it work. Postviews doesn’t count even when Super Cache is off. Do you have a list of compatible plugins or at least those that have conflicts with this?

  12. @sylv3rblade

    Sorry I do not have a list of compatible/conflicting plugins. Please stay tuned, I will be releasing a non-javascript version soon (within the next day or two). Sorry for the delay!

  13. Err no wait.. Scratch that. I forgot about the symbolic link. Umm… does shared hosting even support that? Can I use .htaccess?

  14. @sylv3rblade

    It depends on your shared host. I recommend just moving wp-postviews-js.php directly under your wp-content/ directory if your hosting does not support symbolic links.

  15. Thanks. I got it working now. I think I screwed up the first time because I had a copy of wp-postviews-js.php on both the wp-content directory and the wp-postviews directory

    Thanks again.

  16. Thanks a lot. Just advice to the others, if you activate this plugin, its better to you to delete the cache of wp-super-cache, after activating this plugin.

  17. @sylv3rblade

    I’m glad it works out for you.

    @hendra

    I’m glad it works out for you too, and thank you for your advice.

  18. I will be releasing a non-javascript version soon

    @ Thaya : Than, it still work on wp super cache?

  19. @Rosyidi

    Yes, I will make use of WP-Super-Cache’s add_cacheaction hook to get WP-PostViews to count without Javascript while WP-Super-Cache is enabled. After evaluating the code, there is more work involved than I first thought, but it should be more efficient than the Javascript version when finished.

  20. @All

    Unfortunately, it turns out that I misunderstood the add_cacheaction hook. Previously, I thought that add_cacheaction hook gets called every time before a cached page is delivered. I was wrong and there currently is no such hook available in WP-Super-Cache right now. I will definitely make a request to Donncha to add this to WP-Super-Cache. So as it stands, you are stuck with the JS Mod version of WP-PostViews.

    I have to appologize for getting your hopes up. The WP-Super-Cache code is quite complex (if Donncha doesn’t walk you through it :)), so it took me a while to figure this out.

  21. I think you are expert on wp-super-cache. Could you convert this plugin for wp-super cache?
    http://privism.org/blog/archives/12
    It’s simple plugin I think. Couse only 25 lines.
    Thanks a lot.

  22. @Rosyidi
    Let me look into it. I will get back to you :-).

  23. no image Andy (Check me out!)
    Rate this:
    3.6 (1 person)

    Hi man! Thanks for your small hack. Actually I’m quite some Validation and Clean-HTML-Freak and I found out the Tidy HTML has some problems with the code of wp-postview.php.. Looks like you’d have to change the Javascript-code quite a bit to get it validated. I’m not quite sure if there would be an easier solution than mine, but at least it validates fine and makes no problems… This is for line 76 and following:
    echo ”;
    echo ‘// <![CDATA[';
    echo 'wp_postviews_js_url = "DOMAINNAME/wp-content/wp-postviews-js.php";';
    echo 'document.write("";
    echo '");';
    echo '// ]]>’;
    echo ”;

  24. Hmmm, of course this got f**ed up by the commenting system.. I’ll try again, instead of ** you’d have to use “<”:
    echo ‘**script type=”text/javascript”**’;
    echo ‘// **\/script>”;
    echo ‘”);’;
    echo ‘// ]]>’;
    echo ‘**/script>’;

  25. @Andy

    Thank you for the clean-HTML fixes. I suffer from a mild code O.C.D myself so I totally understand. I will include this change into the zip archive and notify Lester Chan tonight. And please remember to write about it if you like it :).

  26. I have incorporated Andy’s clean-HTML fixes and repacked it into the downloadable zip. Enjoy!

  27. hi.. installed.. but not working (2.5.1) missed anything?
    i cannot make the symbolic link.. i just move the wp-postviews-js.php to /wp-content

    how? example http://funnylolfunny.com/orange-escape/

  28. cool!!!! its working now.. thanks Thaya! you rock!

  29. @funnylolfunny
    I’m so happy every time I get a message like yours. Thank you for the compliment and I’m glad that it works out for you.

  30. no image graphicscale (Check me out!)
    Rate this:
    2.5

    thank very much thaya ^^.


Leave a Reply