Jason Oakley : The life of an Aussie geek!

I use multi-million dollar satellites to find tupperware in the bush!

Random Img Displayer

Donate!

If you find this useful please consider a donation… Clicking the button donates just (AUD) $1.00!


RndImgDisplayer WordPress plugin by Jason Oakley

I wanted to have random images display on the front page of my website, but could not find a plugin for WordPress which automatically created tags for me: alt, height, width. So, I wrote it myself.

To use: Unzip the zip file into a directory on your PC and upload the whole folder to the wp “plugins” directory. No need to edit anything.

Go into your WP admin plugin page and activate the plugin. You will have to size your images yourself. I keep them all the same size to keep it consistent, but RndImgDisplayer will do the size tags automatically regardless.

Create a subdirectory under the rndimgdisplayer plugin folder called “randomimages”. (Sorry. Winzip and *nix zip will not zip up empty directories).

Drop the files you wish to display into this directory.

Add the following code to your template (I use it in my sidebar).

<?PHP displayrndimg(); ?>

If you have any problems with it, turn on debugging and it will output some helpful data for you:

<?PHP displayrndimg(1); ?>

If you want to turn on alt text displayed under the image:

<?PHP displayrndimg(2); ?>

If you wish to turn on image borders use the optional border variable:

<?PHP displayrndimg(0,1); ?>

You can combine both if you wish:

<?PHP displayrndimg(2,1); ?>

I’ve now added a CSS tag for this plugin. You can use it similar to this in your Stylesheet:

/* RndImgDisplayer */

#rndimgdisplayer { background: #000000; color: #ffffff; font-weight: normal; }

Download: RndImgDisplayer1_2.zip You can see the plugin in operation on the front page of my blog.

This plugin is now on the WordPress plugins site with it’s own page.

Update: v1.1: Fix for img src url bug found by James Gemmill. Update: v1.2: Added optional text below image for Jo & Vinnie. Added optional border around image for Jo. Added CSS elements for formatting.

36 Responses to “Random Img Displayer”

  • James Gemmill says:

    Hi,

    This looks great, but my images aren’t displaying, though the alt text is. I tried the debugger and everything seems in order. The page in question is here:

    http://test.throneworld.com/lords01/

    Cheers!

  • WauloK says:

    Ah okay. You don’t have WP installed in the root directory, it’s in a subdirectory “lords01″. I will work on that tonight and release 1.1 if I can fix it. Thanks.

  • James Gemmill says:

    Works beautifully!

    Thanks!

  • WauloK says:

    Glad to hear it James :)

  • Jenny says:

    Lovely, works perfectly and is keeping a client happy..Thank you!

  • Jo says:

    Hey that’s great!

    Couple of questions though – how can I get it to put a border around each image? And also, is there a way of getting to display the title as well as the alt text? I use FF which doesn’t display the alt tag :(

  • WauloK says:

    Jo.
    Sure! I can probably put that together for you soon. Keep checking back. I see I have your email address so I might email you there when this feature is available, too.
    Glad you like it!

  • Vinnie says:

    Great job and thanks, works a real breeze ;-) and yes the option to add alt would be welcome.

  • WauloK says:

    There ya go.. and other updates as well :) Enjoy..

  • Jo says:

    That’s brilliant! Thank you! :D

  • pxyz says:

    hello.. just loaded your picture randomizer.. one feature idea that i would find to be great, would be to allow the user to define multiple directories!

  • WauloK says:

    I’ll see what I can do. I’m pretty busy this weekend, but maybe next one.
    You mean you want to categorise all your stuff into different directories but just pick a random one recursively?
    eg.

    images/holiday
    images/family
    images/pets

  • pxyz says:

    sorry, i didn’t check back as quickly as you responded..

    I was thinking like this.. i have some images that, due to using another blog service and strange habits of users some images in strange directories ..
    so they include
    ../
    ../images
    ../wproot/wpcontent/
    .. and more… !?

    it would be great if one could choose multiple directories that the plugin would go to randomize.. even offsite i suppose!? but if one could just choose a directory and it could find things in subdirectories it could work as well.. in my case i could just specify:
    ../

    it is just an idea… and i figure I can’t be alone!

  • Jo says:

    Eep! Suddenly having problems with it. Although it still manages to display the image and the caption, it also displays tect such as this:

    Warning: getimagesize(): php_network_getaddresses: getaddrinfo failed: Name or service not known in [rootdirectory]/wp-content/plugins/rndimgdisplayer/rndimgdisplayer.php on line 56

    Warning: getimagesize(http://www.josalmon.co.uk/wp-content/plugins/rndimgdisplayer/randomimages/Massie,_2000.jpg): failed to open stream: Success in [rootdirectory]/wp-content/plugins/rndimgdisplayer/rndimgdisplayer.php on line 56

    Stuff in italics is me being coy about the full path!

  • WauloK says:

    Possibly it’s confused with a comma in the file name. Try using accepted characters a-z 0-9 – _
    that’s about it. :) GL!

  • afauzan says:

    Thanks to Jason for his work.
    And how about directory where the images reside? I thought it will be better if we can choose directory the images will be put in.

  • WauloK says:

    Sorry I haven’t had time to look at that yet. Things have been hectic around here.
    I will see what I can do and hopefully have something for the new year.
    I wish everyone a Merry Christmas and a Happy New Year! :)

  • Finally an easy and normal plugin for the random function. Thank you very much!

  • Dtortot says:

    I am runnign WordPress 2.0 and I want to use a random IMG plug in, but all the ones I have tried none work, including yours. I have installed it the way is explained in here and nothing. I found yours to be the easiest to work out, yet I can’t make it work, I end up with no image just the background color.

    I want to use it to randomize my site’s banner/header image, but I can’t make it work. Although if you check it right now, you will see the banner, it won’t change it is the default one and I have 9 different headers. So do you have any idea of what is going on?

  • WauloK says:

    Not really without access to your site. If you followed all the instructions and put the files in the right place it will just work.
    If your current image is created due to the DIV tag, that would be the reason. The DIV will probably overwrite my image code. You would have to leave out the DIV header tag and the onclick.

  • Lilia says:

    Hi Jason,
    thank you very much for such an easy-working plugin – I love it :-)

    Two questions:

    1. is it possible to add a link to the pictures (not one to one, just one link for all – like sending people to a gallery)

    2. is it possible to have one randomized picture per day (not everytime on reload or revisit, but according to date)

    Greetings from Germany
    Lilia

  • WauloK says:

    Lilia.
    I will keep these requests in mind for the next version :)
    Glad you like it!

  • Dtortot says:

    I think it is the DIV tag. If it helps here is the theme I am using for my site: http://marcoss.com.ar/dsgn/equix/

    In any case, thanks for the help, I’ll try to figure it out. And I’ll be on the lookout for the next version. Thanks again.

  • [...] RndImgDisplayer – Damit werden die beiden Bilder im Zuallsmodus angezeigt. [...]

  • [...] Random Image DisplayerEin einfaches Plugin, das aus einem bestimmten Ordner Bilder in zufälliger Reihenfolge anzeigt. [...]

  • [...] RndImgDisplayer [ BILD ] Picks a random image from the subdirectory and displays it with auto tags. By WauloK. [...]

  • [...] 随机文章WordPress plugin 随机图片 RndImgDisplayer完美随机广告代码千辛万苦申请到WordPress.com API key了又换回WordPress了百变图回复(刷新)就变的制作方法 [...]

  • iry says:

    Hi, suddenly i get the same error msg with jo after using the plugin for few months. the name of the images are default03.png which complies with a-z 0-9 format.Any idea on this?

  • [...] Name: RndImgDisplayer Plugin URI: http://www.bangrocks.com/rndimgdisplayer-wordpress-plugin/ Description: Picks a random image from the subdirectory and displays it with auto tags Version: 1.2 [...]

  • Mattias says:

    Great plugin, exactly what I was searching for. Gave it 8/10 on the plugin rating at my site.

    Anyway, is it possible to call the random image function from a separate posting rather than include it in the loop of the site? I´ve looked in the instructions but I can´t seem to realize how I would do it.

    Also, have you found any solution to using multiple directories?

  • jwqlb says:

    works with wp 2.2.2?
    i have great problems with it.

    greetings
    jwqlb

  • Leonaut.com says:

    RndImgDisplayer…

    Picks a random image from the subdirectory and displays it with auto tags….

  • Leave a Reply

    You must be logged in to post a comment.