Random Image Block

The Random Image Block is a small plugin that will display a random image from your native WordPress photo galley or in-beaded images.

This widget will display the thumbnail of the random image, the “caption” and the images parent posts name. You may show all pictures on your site, or limit the selection to a single category if you wish. Once installed on your site, it will fully conform to the current theme. The Widgets title is also fully configurable. Random Image Widget was designed with full internationalization in mind and can be fully translated (Any help on this would be appreciated). As of Version 0.3 this plugin works out of the box without any configuraion (assuming you have pictures on your site).

The Random Image Block plugin works with WordPress 3.0+ in both single and multi site modes. As a Site Admin, you may activate this plugin across all the sites on your install.

This Plugin is fully translated into the following languages:

  • Arabic
  • Czech
  • Finnish
  • French
  • Danish
  • Dutch
  • German
  • Indonesian
  • Italian
  • Portuguese
  • Russian
  • Spanish

If you would like to help translating this plugin, or you see a problem with the current translation, please see my Translation page, and/or contact me.

Download

Latest version: Download Random Image Block v0.10 [zip]

Installation

As with most WordPress plugins, there is two ways of installing this plugin.

Primary Option

  1. Go to your WordPress Dashboard and login as an Admin
  2. From your Dashboard go to Plugins section on the left hand side and select Add New.
  3. Search for Random Image Block
  4. Click the Install Now link and follow the instructions.

Secondary Option

  1. Download the latest version from the download page (https://wordpress.org/extend/plugins/random-image-block/)
  2. Extract the zip file and copy the folder “random-image-block” into the “wp-content/plugins/” directory in your WordPress installation.
  3. Activate the plugin from your Dashboard by going to Plugins -> Installed page.

Screen Shots

  1. The Random Image Block on the front page, conforming to the current theme.

    The Random Image Block on the front page, conforming to the current theme.

  2. The Wiget Admin page for the Random Image Block.

    The Wiget Admin page for the Random Image Block.

FAQ

Q. Q: May I have more the one image on my sidebar?
A. A: Sure, just add a second or third widget to the sidebar, but you can’t do it from within this widget.

Q. Q: May I display more then one category at once?
A. A: No, you may only display a single category per widget

Q. Q: I have no picture in my sidebar, the widget doesn’t work!
A. A: Make sure the category you have selected has pictures in it, if it doesn’t, nothing will be displayed.

Q. Q: Will this plugin work with WP Super Cache enabled?
A. A: Unfortunately, no. WP Super Cache caches all php built html pages for quicker page loads. Since the Random Image Block is built directly into the html page, with WP Super Cache enabled, you will see the same random image on the same page until the cache refreshes. Each page will still have a diffrent image, but they will not update for each page refresh. Currently there is no work around.

Changelog

Version 0.10

  • removed depressed calls to attribute_escape

Version 0.9.2

  • Fully tested for WordPress version 3.1

Version 0.9.1

  • Fixed bug where default options were always on.

Version 0.9

  • Added Advanced Options
  • Allow for custom Meta data
  • Added Tranlation for: Arabic, Czech, Danish, Dutch, Finnish, Indonesian, & Russian

Version 0.8

  • Added ability to link to the album vs the image.

Version 0.7

  • Changed to dropdown box for category selection, translaion files have not been fully updated, yet.

Version 0.6

  • Added ability to center image in the wiget area

Version 0.5

  • Switched to ‘{$before_widget}{$before_title}’… to try and resolve some display problems

Version 0.4

  • Translated into: French, German, Italian, Portuguese, & Spanish

Version 0.3

  • Fixed bug that showed no picture if the category box was left blank.
  • Single Category check box now works.

Version 0.2

  • Added check box to allow single category.

Version 0.1

  • Everythings new!

84 thoughts on “Random Image Block

  1. Hi, thanks for this plugin.
    How to show total number of images from category? In var $noimages contains only total number of all images in media library … ๐Ÿ™

    • The count you see on this site is a function of the theme, not this plugin. But it’s not to much to add to your theme if you would like to.

      The code im using is part of the gallery index, but you may put it anywhere within the post loop.

              <?php $num_gallery_posts = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_type = 'attachment'" );
              if ( $num_gallery_posts > 1 ) {
                ?><div id="gallerypost_sub_right-<?php the_ID(); ?>" class="gallerypost_sub_right">
                  <small>This Album contains <?php echo $num_gallery_posts; ?> items.</small>
                </div>
              <?php } ?>
      
  2. I had a cod that woth wordpress give me a picture and I want to show that size…

    which is 310 x 265 px

    there is a function which I put it give me a thumbnail with this size.

    “”)); ?>

  3. Hi Mate, don’t suppose there is any chance of getting a shortcode for this? It would be awesome if you could drop this into pages, for example a shortcode for the image with options for image size (small, med, large as per media manager). Some sites would like this to be a main feature on a page rather than just a small part of the sidebar.

    It would be great if you could specify the image size in the widget options.

    Great plugin! ๐Ÿ™‚

    • Here’s what I used to insert a random large from all categories.

      // Generate random image
      function random_image() {
      
          $riw_cat_id = "-1";
          global $wpdb;
      
          $args = array(
              'post_type' => 'attachment',
              'post_mime_type' => 'image',
              'numberposts' => -1,
              'post_status' => null,
              'post_parent' => $post->ID,
              'orderby' => 'rand'
          );
      
          $attachments = get_posts($args);
          $noimages = count($attachments);
          if ($attachments) {
              foreach ($attachments as $attachment) {
                  if ( $riw_cat_id !== "-1" ) {
                      $albumid = $attachment->post_parent;
                  } else {
                      $albumid = $attachment->post_parent;
                      foreach((get_the_category($albumid)) as $category) {
                          $riw_cat_id = $category->cat_ID;
                      }
                  }
          
                  if (in_category($riw_cat_id, $albumid)) {
                      $imgid = $attachment->ID;
              
                      // construct the image
      				echo "";
                      echo wp_get_attachment_image($imgid, 'large');
      				echo "";
                      break;
                  }
              }
          }
      }
      random_image();
    • As the plugin sits right now, you can’t.

      You will need to modify the source to pull the external URL from the database somewhere so WordPress may link to it, but that functionality is not built into the plugin.

      -Matt

  4. I’m testing the plugin, and I get an occasional error message that shows instead of an image, when refreshing the page (in Chrome, IE and FF):
    Fatal error: Cannot use string offset as an array in /wp-content/plugins/random-image-block/random-image-block.php on line 86

    • The plugin uses the thumbnail image from your media settings. You can change your thumbnail size, or you may modify the plugin to use a different image base, but it can not be changed out of the box as it is now.

  5. Hi Matt,

    Is there a way to have the images changing randomly, not only when refreshing page?
    Could I then also define the timing of this?

    Thanks!
    Monika

  6. Hi, another issue I am having. It’s showing photos that are not associated with any posts, like my web design photos like banners etc. I thought it would only look at images associate with a post? Am I missing a setting?

    Thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.