Categories
Package/plugin/module WordPress

Random File v1.5

I’d like to announce the official release of the updated Random File plugin (v1.5) for WordPress.

Retrieve the name, path, or link to a randomly chosen file in a specified directory.

The plugin’s official homepage is located at :
coffee2code.com/wp-plugins/random-file.

This release introduces a new reftype of ‘hyperlink’, which returns the filename of the random file hyperlinked to that file. It also adds a variety of error checks and small plugin tweaks. The release also brings with it full compatibility with WordPress 2.3+ and 2.5 (with continued support for 1.5+, 2.0+, 2.1+ and 2.2+).

This update is part of coffee2code’s 14 Days of Plugins (updated plugin #6).

Update: Plugin updated to v1.5.1 (see comment below for more information)

Update: Plugin updated to v1.5.2 (see comment below for more information)

Comments welcome on this post for this version of the plugin. Comments will be closed once this release has been superseded by another.

Read more for a detailed ChangeLog of the release.

Detailed ChangeLog

These are the detailed changes, which may or may not make sense to you depending on your familiarity with the previous features and internals of the plugin.

  • Added new reftype of ‘hyperlink’ to return the filename of the random file hyperlinked to that file
  • Added error checking to avoid error when referenced directory does not exist
  • Added error checking for when there is an error opening a directory

  • Explicit handling of reftype ‘absolute’ in the code was actually supposed to be ‘serverabsolute’
  • Minor code tweaks
  • Tweaked installation instructions
  • Added compatibility note
  • Updated copyright date and version to 1.5
  • Added readme.txt
  • Tested compatibility with WP 2.3.3 and 2.5

15 replies on “Random File v1.5”

I wanted random code included within my header, so…

I created a directory ‘random’ within wp-content and added the following line to my theme:

Using the default relative path did not work. It would randomize the file but the “include” function wanted an absolute value which would always result to my theme directory. Also the call to “virtual” did not work.

I then found that since you are now stripping off the beginning and trailing slashes, I would end up with a truncated path or both the directory AND file name and the call to include would fail.

I modified the following line in random-file.php to add the trailing slash between my new directory and the actual file name.

} elseif ( ‘absolute’ == $reftype ) {
return $abs_dir . ‘/’ . $random_file;

The code was removed probably because of the php tags so here is what should have been included in the previous post for the code in my themes header.php (without the “< ? php” part)

include(c2c_random_file(‘wp-content/random’, ‘txt’, $reftype=’absolute’));

v1.5.1 of this plugin has been released

This release fixes a missing ‘/’ in the path construction for reftype ‘absolute’.

(Thanks, pingram3541!)

It’s true that you generally need to edit a template file to make use of the plugin, which is really how to expose the true flexibility of the plugin. However, I do have widget functionality in mind which may suit you. Keep an eye out for an update to the plugin (though I can’t estimate a release date for it).

Is it possible that the new security measures in 2.8.4 generate issues with the plugin?

I noticed a high load after upgrading, and noticed that pages weren´t being cached. Wp Super Cached added “Page not cached. No closing html tag found” on the line prior to executing the call to the random plugin (although the page loads/generates completely). If I remove the line calling the plugin, it works fine, and the page is cached.

mike: I would imagine there is a plugin that more directly does that very thing. Depending on precisely what you’re going for, you could probably achieve it with this plugin, but it’d be a bit round-about and manual.

david: Interesting; thanks for the report. I’ll investigate the issue.

I’m implementing this into a site here:
saintbenedictstable.ca/

Randomizing images works great (see small image near top of left sidebar). But I can’t seem to get the text to work. I noticed that your .txt “possibly” requires Apache, so maybe that’s not working for me. I switched it to the .php version include(c2c_random_file('wp-content/random', 'php')); with every possible variation of leading and trailing slashes, and I’m still getting the error you see there. If you paste the path to the file that it says is missing, you’ll see that it is, in fact, there. What am I missing?

Thanks for any help!

Actually, I think that it has something to do with “added” content, as I´m having a similar issue with the Comments Rating plugin. When someone votes, the vote count changes… and the “new” HTML used as the output also adds “Page not cached. I reported this to the plugin developer and he fixed it.

v1.5.2 of this plugin has been released

This minor release does the following:

* Add PHPDoc documentation
* Note compatibility with WP 2.9+
* Update copyright date
* Update readme.txt

Dear Scott,

Than you for the great plugin!

I would like to ask if it would be possible for you to make a enhancement to the plugin.
It would be simply fantastic if this plugin also could interpret (run) PHP code.

Regards

Hi…. I really like this plugin. Very easy to use.

Is there a way to retrieve more than one random file at a time? So, if I wanted to pull three random text files from a directory of many text files, is that possible? I guess the caveat is that I want to ensure that I don’t use the same file twice on a single page load. Otherwise, I’d just call the function 3 times.

Thanks.

Scott, thank you for this plugin and all your work.
I would like to use the “random file” to randomly change the background image on my WordPress site…
At the moment I have in the style.css:
body {background:#000 url(images/bodybg.jpg) top center no-repeat fixed; font-family:Arial, sans-serif; text-align:center; padding-bottom:20px; text-shadow:0 0 4px #444;}
How can I implement your code into the actual url(images/bodybg.jpg) so there is a random image displayed instead?
Sorry if this is a trivial question, but I am new at this and it seems that your code needs to be inserted into a template file, so I don’t know exactly how to call the function into the style.css file…
Thank you very much in advance for your help 🙂

Comments are closed.