Plugins,  WordPress

New WordPress Plugin: Top 10

Last week I gave you Contextual Related Posts and Moderation Author Notify. Have spent almost the whole of this week rewriting Mark’s original Top 10 plugin. And, that sure has been a rather interesting, frustrating and of course fulfilling journey in PHP in general and WordPress in particular and I still believe I’ve not even scratched the surface of PHP, SQL and WordPress!

Anyway, I began with duplicating the original functionality of the plugin, however, ensuring that this strictly followed the latest Plugin API recommended by WordPress.

So, a few things that were changed / added were:

  • The table to store the statistics now has the prefix (wp_) by default. So, if you have multiple blogs stored in the same database with different prefixes, this plugin will not mess up the stats.
  • An options page to set the text you want displayed for the counter as well as for the popular posts
  • Uninstall support so that all changes by the plugin are reversed on deletion from within WP-Admin. But, why would you?
  • Ability to automatically add the viewed count to your single posts and pages.

Having all this in place, I ran a test on my blog Techtites and was pleased with the results, except for one major bottleneck. With WP Super Cache disabled the plugin tracked page views and displayed the counts correctly. However, the moment I enabled the cache the plugin would no longer update, and the page views were singe.

So, began the long and painful process of researching and figuring out how to bypass the cache. Well, to make a long story short, you can’t bypass the cache. However, what you can do is use JavaScript or AJAX for the same. Fortunately, the WordPress Codex has a well written article on using AJAX in Plugins. I was able to implement the same into the plugin.

This is where I would like to thank Thaya Kareeson for his help on the same. He kindly went through the code and helped me debug. We found out that the plugin counter updated properly. However, to display the count would require some more AJAX / JavaScript. Thaya is known for his super-awesome plugin WP Greet Box [my review on WLTC], which I have running on this blog as well as Techtites.

I finally decide to implement the count display using a mix of PHP and JavaScript. I’ll blog about this later today on Techtites (subscribe).

After some rigorous testing, I give you Top 10 – A Page Counter and Popular Posts plugin for WordPress.

So why don’t you download and install it on your blog. I have a lot of feature additions planned for this plugin and as usual I’m open to all suggestions and feature requests. Do comment here or on the plugin page directly with the same.

(Visited 414 times, 1 visits today)

4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.