AJAX Random Posts
Firstly, I’d like to show off a bit: hey I’ve caught up with the crowd, now both of my sites (this one and Thica.net) are upgraded to WordPress 2.7 – well, let’s hope that it is not prone to new vulnerabilities. The most significant change is the admin section – for the first time in my life I have to admit that it looks even better than the front-end. Is it good, or is it bad (my baby), I don’t know, but if you are using my plugin(s) and are worried about the compatibility, rest assured: they all work in this new versions. That is, of course, unless you tell me that they’re not.
But hey, this post is not about WordPress 2.7! There are hundreds of blogs out there babbling about it already! If you’re a careful reader (definition: a careful reader is someone who reads something from the title on), you probably know it, I’ve managed to used some free time to write another WP plugin called AJAX Random Posts, and this post is more or less its homepage.
As its name is saying, AJAX Random Posts (AjaxRP) display a list of randomly chosen posts from your WordPress-powered blog. Yeah, it’s nothing new, such a concept is very popular and has been greatly done by several plugins before. The limitation of those plugins however, is the lack of cache plugins compatibility. For example, you install a random post plugin. Then a visitor comes to post A, and under a post he’s served with 5 other random ones, let’s say C, Y, M, K, and J. If you have WP-Super Cache enabled on your blog, the post A is cached for, like, one hour. During that one hour, any visitor that reads post A will be served with its cached version, with C, Y, M, K, and J following. You must agree with me, it’s not so random anymore .
So, the only difference my AjaxRP is making is its “AJAX” part. With AjaxRP, the random list is NOT generated along with post A. Instead, it makes an AJAX call to the server after the page is loaded (more precisely, after the DOM is ready) and retrieves a list of random posts. This way, it works regardless of whether or not you have a cache plugin installed. That means, each page refresh shows a new random list. And I guess that is what should be called “random”.
Q: Do you provide a template tag/ post tag?
A: Absolutely. If you don’t want the random posts to be display after every post, just set “Automatically display the random posts in a single post page?” to “No” in the Settings page, and
- Manually put <!–ajaxrp–> at the end of your post, or
- Place this php code: <?php if (function_exists(‘ajaxrp’)) ajaxrp(); ?>
at a proper place in your template’s single.php page
Q: Where can I find a demo?
A: Right here! Take a look at the end of this post.
Q: How do I support this plugin?
A: Please link back to this post or blog about it. Also I would appreciate a lot if you can rate this plugin 5 stars in the WordPress repository.
Full history can be found here.