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”.

FAQ

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.

History

Full history can be found here.

Download

Head here.

  • Hi!Thanks for the plugin, can i place the random post in a widget?
     

  • Hi, after succesfuly instaled Ajax Random Post, look what i want to do:
    I want to ad a section in sidebar “My best posts” (5 or 7) random selected urls from a predefined 40-50 url’s.  Not all post, not cathegory or tag involved. Do you know a plugin who make this job, i didn’t find one.
    I find one plugin working based on setting custom field in post but without function random and limiting output number.
    Can you help me please? An advice or a little script?

  • One is ‘Blink’ by Gladwell. ,

  • When I enable this plugin, my posts will load, and then as soon as the page is done loading, it refreshes and gets stuck in a loop. What can I do?

  • This plugin rocks! Unfortunately, I get not settings page, so can’t use it.
    Doesn’t appear in WP 2.9 dashboard…

  • This is a great plugin and very useful to help readers explore my site.  I just have a problem with the {authorurl} and {author} fields.  They don’t link to the right place.  Any ideas?

  • Hi, this is an amazing plugin. Is it possible to display random posts from a particular category rather than all categories.. Thanks

  • Does it show thumbnail? Is is possible only to show random thumbnails?

  • Maybe its just me but I don’t see a demo at the end of your post.  I also cant get it to work on my WP blog version 2.9.2.  Am I doing something wrong??

  • Maybe its just me but I don’t see a demo at the end of your post -> My mistake, as this “post” is actually a page. See any other post and you will see the plugin working.

    I also cant get it to work on my WP blog version 2.9.2. Am I doing something wrong?? -> Idk, it seems.

  • WordPress 2.9.2 - installed from plugin search, configured a little bit and works like a charm! Thank You!

  • Thank you, the script is very cool!
    Is it possible to make it to display a small thumbnail from the article too? :)

  • Does it also work with WP 3.0? Plugin activated, <?php if (function_exists(‘ajaxrp’)) ajaxrp(); ?> placed in my single.php and nothing happens.

  • Bug found in wp 3.0.1
    Let’s say my list is set in wp-admin to contain 3 posts.
    And I have 3 sticky posts in my blog.
    My list will look like this:
    1. - sticky (not random)
    2. - sticky (not random)
    3. - sticky (not random)
    4. - random post
    5. - random post
     
    6. - random post
    Too many! huh?
     

  • Daniel, it does work with 3.0. Problem(s) must be somewhere.
    Try var_dump(ajaxrp()) and see the output?

  • Hah, that makes sense Andrian. Apparently it didn’t take into account the sticky posts. Let me do a check.

  • Can you make a feature to extract image from a post

  • Any plans to include the thumbnail in the next future release? I like the ajax part of this plugin.

  • it’s not randomizing and not posting the numbers of posts I want (it’s posting only one)
    after checking the “sticky posts” options, it doesn’t randomize anymore (even if unchecked)
    i’m using latest stable version of wp

  • Really great plugin. Keep it up!
    However, It breaks up in the wordpress version 3.2.1. Says, some undefined variables, and use of deprecated function.
    Are you planning to release a new update soon?

  • yeah…it good plugin for my blog…..

  • I just wanted to say that I loved the plugin, but I had to deactivate it because there was a conflict between it and WP E-Commerce. I guess WP E-Commerce must use AJAX, too. What was happening is that when people clicked on the “Add to Cart” button, it would actually add that item to the cart, but the spinning wheel never stopped spinning, so people thought the cart was hosed.

  • It’s a great plugin. Unfortunately, it does not offer a featured thumbnail. Would it be possible to add thumbnails on each random post list?

  • I do hope the author can update this great plugin.

  • You guys are asking for thumbnail. My problem is that Ajax random post is showing big thumbnails in my site. How do I remove it?

    I just added this code in functions.php and everything goes berserk.

    function InsertFeaturedImage($content) {

    global $post;

    $original_content = $content;

    if ( current_theme_supports( ‘post-thumbnails’ ) ) {

    if ((is_page()) || (is_single())) {
    $content = the_post_thumbnail(‘page-single’);
    $content .= $original_content;
    } else {
    $content = the_post_thumbnail(‘index-categories’);
    $content .= $original_content;
    }

    }
    return $content;
    }

    add_filter( ‘the_content’, ‘InsertFeaturedImage’ );

You can follow any responses to this entry through the RSS 2.0 feed.