Random Posts

Purpose

This plugin displays a list of posts chosen randomly from your blog.

This is version 2.6.0.1 download latest version. It is compatible with WordPress 1.5–2.6.

Please note the new upgrade instructions!

Note: If you had the misfortune to download version 2.5.0.7 you may run into problems when you try to update to a newer version. I managed to introduce a circular dependence between this plugin and the Post-Plugin Library which means trying to update either from the admin plugins page will cause an error. Instead you need to delete the 2.5.0.7 version from the server and upload the newer one and the problem should be solved. I apologise for any worry or inconvenience.

Random Posts lets you put on display some of the posts that might otherwise get lost deep in your archives and, hopefully, get visitors to explore your site more thoroughly.

The plugin has an settings page which lets you change how the output is generated and displayed.

Installation Instructions

  1. If upgrading from a previous version, first deactivate the plugin via the Plugins page and delete the plugin folder from your server.
  2. Upload the plugin folder to your /wp-content/plugins/ directory. You will also need to install the Post-Plugin Library.
  3. Go to your admin Plugins page and activate Random Posts.
  4. Put <?php random_posts(); ?> at the place in your theme files where you want the list of similar posts to appear. Lorelle on WordPress has a good guide to modifying themes for plugins. If you are using a widget-ready theme the plugin can be placed from the widget admin page.
  5. Use the admin Settings|Random Posts pages to set all the available options. Alternatively, the options can be overridden by passing a parameter to the random_posts template tag.

Usage and Options

The configuration page will help you to set up the plugin to your satisfaction.

Finally…

I look forward to your help in ironing out any issues and implementing any good ideas. The plugin settings page has an option to submit bug reports but general comments can be left below.

Frequently Asked Questions

  1. Rating: +0


    Positive


    Negative

    How do I get it so that {link} displays the date instead of the title? If i use the {date} template tag, it shows the date but no link.

    You need to use the output template to tell the plugin exactly what to display. For example, if you want a link where the visible text shows the date of posting you could try:

    
    <li><a href="{url}">{date}</a></li>
    
    

  2. Rating: +0


    Positive


    Negative

    How do I format the output of the {date} tag?

    The blog’s date format is used by default but you can change it by adding a format string. The Codex has a page on format strings. Let’s say you want the date to look like Sunday, January 14, 2007. The correct format string is ‘l, F j, Y’ so you would write

    {date:l, F j, Y}

  3. Rating: +0


    Positive


    Negative

    I don’t want my post plugin widget to show on the main page, just the single post page. Is that possible?

    Yes. The widgets now let you choose the condition under which they are visible. The condition can be set using any combination of WordPress Conditional Tags, e.g., ‘is_home()’, ‘is_category()’, or ‘is_page()’.

    In this case the right condition is ‘is_single()’.

  4. Rating: +0


    Positive


    Negative

    I’m trying to place the plugin output just after a single post but other plugins seem to get in there first. Any ideas?

    Some plugins automatically tack on their output to the end of a post’s content. The only way to get something in between is to hope that those plugins offer a way to turn off that kind of behaviour and let you explicitly place their output with a template tag. The good news is that most plugins are cooperative.

  5. Rating: +0


    Positive


    Negative

    I found a script that allows me to put thumbnail images [or anything else] with each post. I was wondering if there was a way to integrate that with this plugin?

    If the script stores the thumbnails in a custom field you can use the output template tag {custom} to display them. Try
    something like:

    
    <img src="{custom:thumbnail}" alt="{custom:thumbnail-alt}" />
    

    A similar thing can be done with many other plugins.

  6. Rating: +0


    Positive


    Negative

    I want to show the same plugin in two different places but with different output: can I?

    Yes. Decide on one of the output templates and other settings you need and set them up from the options pages. The other invocation of the plugin then gets called with passed parameters to get the different output.
    e.g., random_posts('limit=3&output_template={custom:another_field}')

  7. Rating: +0


    Positive


    Negative

    I want an output template tag to do xxxxxx. How do I invent one?

    You have two choices: a) modify the output_tags.php in the post-plugin-library; b) use the {php} tag.
    If you go down route (a) (which is actually very easy) please let me know the new tag and I’ll maybe include it in the next version. If you use the {php} tag do be careful not to start WWIII.

  8. Rating: +0


    Positive


    Negative

    I uninstalled one of your plugins and now my whole sidebar has disappeared. How do I get it back?

    You have probably forgotten to remove the code calling the plugin, e.g., recent_posts();.
    I find a good practice is to use something like:

    
    if (function_exists('recent_posts')) {
      recent_posts();
    }
    

    That way, if I ever deactivate a plugin temporarily the website doesn’t fall apart.

40 Comments Add your own

  • 1. Rob  |  March 17th, 2008 at 6:19 pm

    Version 2.5 b3 posted

  • 2. dissi  |  April 3rd, 2008 at 11:15 pm

    hello,

    this plugin nearly matches what i was looking for.
    but to be honest i would prefer to write an include-list instead of a list of posts to exclude. because i just want to display some of the best articles so far randomly. since i have nearly 500 posts it would be a lot of work to exclude a majority instead of including a small collection. :(

  • 3. Rob  |  April 3rd, 2008 at 11:20 pm

    dissi: that would be easy to add — I just never thought anybody would have a use for it.

  • 4. Partz Partzescu  |  April 3rd, 2008 at 11:39 pm

    Hello Rob,

    Can you please update somehow the plugin so i can modify the title of it, it appears Recent Comments but my blog isn’t in English so i have to say it in my language. Thanks!

  • 5. Partz Partzescu  |  April 3rd, 2008 at 11:40 pm

    I forgot, can you also add the number of posts that should show like in your other plugins?

  • 6. Rob  |  April 3rd, 2008 at 11:56 pm

    Partz Partzescu: Both those options are already there. Maybe I am not understanding what you mean?

  • 7. dissi  |  April 4th, 2008 at 12:06 am

    @ rob: that sounds very promising :)
    maybe you like to consider to add this option in one of the next updates, perhaps it is possible to put it in some kind of “reverse mode”, giving the list the opposite function (using it for including instead of excluding). that would be brilliant.

  • 8. Partz Partzescu  |  April 4th, 2008 at 10:54 am

    Ok i think there is a BUG, when i try to remove the widget from the sidebar, i can’t because the menu is not there. The edit button is missing. I use wp2.5. All other plugins from you work correctly

  • 9. Rob  |  April 4th, 2008 at 12:15 pm

    Partz Partzescu: I can’t reproduce that behaviour myself. Can you make a bug report from the settings screen of Random Posts because it will tell me stuff about version numbers, etc.

    I would also advise uninstalling the plugin completely and installing the latest version.

  • 10. Partz Partzescu  |  April 4th, 2008 at 12:33 pm

    Ok, no problem i’ll do it right now

  • 11. Rosina Lippi  |  April 17th, 2008 at 4:53 pm

    Rob,

    I had been using this plugin without any hiccups until just recently. To be honest, I don’t know when it simply disappeared from the sidebar — but I noticed today that it was gone.

    So I checked the configuration page and I also took the widget off the sidebar and put it back on. No luck.

    Then I put the php code in a php enabled widget, but still no luck. The random posts pluging just won’t come out and play. And it’s such a great plugin too, I think it’s done a lot for my ‘how-long a person sticks around’ stats.

    Any suggestions much appreciated.

  • 12. Rob  |  April 17th, 2008 at 5:11 pm

    Rosina Lippi: Can you tell me what version of WP and of RP you are using? And can you tell me if anything else has changed recently — updates, new plugins, etc. Thanks.

  • 13. Rosina Lippi  |  April 17th, 2008 at 5:32 pm

    Sorry Rob, I should have thought to include that information.

    I’m on the most recent, up-to-date versions of WP and Random Posts (2.5; 2.5b19). I do have a lot of plugins installed. Are there any in particular that don’t get along with Random Posts?

  • 14. Rob  |  April 17th, 2008 at 5:35 pm

    Rosina: I’ve had the odd report of the recent posts plugin not doing well with wp-cache. I was just wondering whether anything notable had changed which might help me get to the root of the problem.

    Could you make a bug report through the settings screen as it provides some extra information that might help.

  • 15. Rosina Lippi  |  April 17th, 2008 at 5:41 pm

    Done. Thanks for your help.

  • 16. Ace  |  April 23rd, 2008 at 1:28 am

    Love the idea of having a random post widget. I went through all the steps, installed and activated the necessary plugins. Added the widget to my sidebar, and it messed up the whole page (which I half expected because the site is currently using a pretty complex theme). But the real problem is that now I can’t get rid of the widget.

    As I look at my design-widgets screen, I added the Random Posts widget. It moved over to the right of my screen and says that I am now using 1 widget. After I discovered it wasn’t working, I wanted to remove the widget, but leave the plugin for now. But I can’t for the life of me figure out how to remove the widget. Is there supposed to be a way?

    As of right now, the only thing I can do is deactivate the plugin. That removes the widget from the right side of my design-widgets screen, but it still says that I am now using 1 widget.

    Is it normal that once you add this widget you can never get rid of it short of getting rid of the plugins? Thanks for any help you can offer.

  • 17. Ace  |  April 23rd, 2008 at 1:39 am

    I now realize I brought this on myself by not closely following the above instructions.

    But that said, I really don’t know what do it. I completely deleted the plugins, and it still says that I’m using 1 widget (but there’s nothing there).

  • 18. Ace  |  April 23rd, 2008 at 1:52 am

    Sorry for the triple post.

    Conclusions:

    1.) I’m an idiot.

    2.) This plugin is awesome. Thanks so much.

  • 19. Rob  |  April 23rd, 2008 at 10:53 am

    Ace: Is everything working properly now? If the widget is not showing the ‘edit’ link to let you remove it something has gone wrong.

    As for WordPress telling you there is a widget inuse when there isn’t … that seems to be a WordPress bug.

  • 20. kca  |  May 1st, 2008 at 10:00 am

    Hello,

    Thanks for your work, i really appreciate.
    Just a silly question: What is the string name to unable WPcache to cache the radom post (i use the thumbs)?

    Best regards

  • 21. Rob  |  May 2nd, 2008 at 10:52 am

    kca: I’m sorry I don’t understand. The WP-Cache plugin will cache the output automatically. Is that what you mean?

    My own Plugin Output Cache won’t automatically cache the Random Post output because I wanted to keep it dynamic.

  • 22. KCA  |  May 2nd, 2008 at 11:48 am

    Thanks for the quick answer.

    Sorry lost in translation.
    In fact my question is: How to keep the random post dynamic with WPcache?

  • 23. Rob  |  May 2nd, 2008 at 2:36 pm

    KCA: Ah! I tried that myself a while ago and basically found I had to include so much of WordPress that it wasn’t worth it. I seem to remember I had to include some path information in the string but I can’t be sure.

  • 24. kca  |  May 2nd, 2008 at 4:42 pm

    Thanks Rob,
    guess what? I will just keep it simple. I am already satisfy with the plugin, and it will not be too hard for me, to just clean up the cache 1 time/ day at least ^o^

    Best Regards

  • 25. Rob  |  May 2nd, 2008 at 5:58 pm

    kca: Maybe there’s something you can do with the wp pseudo-cron functionality?

  • 26. Copernicus  |  May 14th, 2008 at 6:18 pm

    Hi Rob: thanks for the great plugins!

    I’m using RecentPosts on a site & have employed the tag {categorynames} to display the category (or categories) in which a listed post resides. However, when a post resides in multiple categories it lists the category names back-to-back with no spaces. For example, a post within the categories of “News” and “Reviews” shows up as “NewsReviews”

    Am I doing something wrong? Or is there something I can edit to make it display properly?

    Thanks!

  • 27. Rob  |  May 14th, 2008 at 9:36 pm

    Copernicus: You can specify a separator string in the extra part after the colon, e.g.: {categorynames: | }

  • 28. john  |  May 20th, 2008 at 12:12 pm

    Very useful - especially to improve site indexing.

  • 29. rick davies  |  May 21st, 2008 at 9:50 am

    My sidebar is already crowded

    Is there anyway I can just put a text link “Random Post” on the side bar (preferably in the next row under my Search button), and when people click on these words the random listing appears on a new page/post to the left?

  • 30. Rob  |  May 23rd, 2008 at 10:15 am

    rick davies: There a number of ways of doing that. Perhaps the easiest is to make a new page dedicated to the random listing and use the embedded tag <!--RandomPosts--> somewhere in its content. You would need to switch on the content filter to have it appear. Then just put a link to the page as normal in your sidebar.

  • 31. Rob  |  June 4th, 2008 at 10:41 am

    If you had the misfortune to download version 2.5.0.7 you may run into problems when you try to update to a newer version. I managed to introduce a circular dependence between this plugin and the Post-Plugin Library which means trying to update either from the admin plugins page will cause an error. Instead you need to delete the 2.5.0.7 version from the server (Post-Plugin LIbrary too) and upload the newer one and the problem should be solved. I apologise for any worry or inconvenience.

  • 32. DavinaH  |  June 28th, 2008 at 2:36 am

    Hi Rob.

    I’m looking forward to trying out this new plug-in. I currently only have 2 posts on my new blog, so it could be some time… but I think it’s a great idea.

  • 33. Jude  |  July 10th, 2008 at 4:38 am

    Is there any way to get the image src title?

    Also, can I put {imagesrc} in a replace function?

    Thanks for this plugin. It’s great stuff.

    amdg

  • 34. Rob  |  July 10th, 2008 at 10:42 am

    Jude: Nice site!

    I’m sorry to say those abilities are missing right now. If you can tell me more exactly what you are looking for I might find that they would be easy to implement.

  • 35. Jude  |  July 10th, 2008 at 4:22 pm

    Thanks!

    Basically I want to get {imagesrc} string and replace “.jpg” with “-150×150.jpg” so it ends up displaying the thumbnail that wordpress generates when I upload pictures.

    imagesrc title was also an option because it’s the same as the image filename (without the file extension).

  • 36. Rob  |  July 12th, 2008 at 5:11 pm

    Jude: I think the best solution from my point of view would be to allow output tags within the {php} output tag. I’ve already done that for the {if} tag so it shouldn’t take much effort.

    An alternative might just be to make an output tag {thumbsrc}. Does WordPress always use that naming convention–i.e., is it always 150×150 or can the size vary?

  • 37. Rob  |  July 12th, 2008 at 10:30 pm

    Jude: Version 2.5.0.11 has beefed up the {php} tag to allow tags to be used in code, e.g:

    {php:echo str_replace('.jpg','xxx.jpg','{imagesrc:0}');}

    Note the quotation marks around the {imagesrc} tag.

    By the way — I’d still consider making a tag to do the job directly if you can help me with some information.

  • 38. Jude  |  July 13th, 2008 at 2:24 am

    Rob, works perfectly. As a quick workaround, I added the replace function in the output tags php but the new updates are definitely a much slicker solution.

    The thumbnail size is user-defined in settings > miscellaneous. 150 x 150 seems to be the default size

    Thanks!

  • 39. moserw  |  July 13th, 2008 at 12:59 pm

    Have this on my blog and it works great. Have been using it for a while. Dropped by to say thanks and much appreciated.

  • 40. Rob  |  July 13th, 2008 at 9:28 pm

    moserw: Thanks! Glad it does the trick for you.

Leave a Comment

Required

Required, hidden

Trackback this post  |  Subscribe to the comments via RSS Feed