Really Simple Gallery Widget

Yes, it’s yet another plugin born out of a specific work request that seems usable by the general public. We’ve got some pages that function as photo galleries and we like to show said photos in the sidebar in a random order with a link to an anchor on the gallery page or showing the full-size image in a Shadowbox overlay. Turns out that the built-in gallery shortcode doesn’t actually do random (as far as I could tell) and shows captions by default and all kinds of things that just weren’t working for me (or the people I report to). I looked through and tried out a pretty ridiculous number of plugins, many of which required the use of separate galleries or new posts of a custom post type, and none of which did what I needed them to do – just use the built-in attachment functionality.

So, I wrote a widget and then made it into a plugin that does more than what I originally needed. A couple examples:

Available shortly now in the WordPress plugin repository: http://wordpress.org/extend/plugins/really-simple-gallery-widget/. Here’s all the stuff from the readme file:

Really Simple Gallery Widget

Donate link: http://www.helenhousandi.com/wordpress/donate/
Tags: gallery, widget
Requires at least: 2.8
Tested up to: 3.1

Simple widget for displaying images attached to a specific post or page.

Description

Really Simple Gallery Widget adds a widget to display images that are attached to a post or page, no extra uploading or creating custom post types required. Especially helpful if you create photo gallery pages using the built-in WordPress gallery and just want to be able to display those images in a widget area.

Features

  • Add as many widgets as you want, wherever you want
  • Select a number of images
  • Select any registered size in WordPress
  • Display the images in ascending, descending, or random order
  • Show or hide captions
  • Link the images to the original file, post, anchor in the post, attachment page, or nothing
  • Add a prefix to the link and image title (appears as a tooltip)
  • Use a rel attribute for the link – great for lightboxes

Installation

Really Simple Gallery Widget is most easily installed automatically via the Plugins tab in your blog administration panel. Go to Appearance -> Widgets to set one or more widgets up.

Manual Installation

  1. Upload the really-simple-gallery-widget folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Head over to Appearance -> Widgets to set up one or more Really Simple Gallery Widgets

Frequently Asked Questions

How do I get the ID for the post or page?
The easiest way is to mouseover or click an edit link for the post or page in question. The ID number will appear in the URL; e.g. http://yoursite.com/wp-admin/post.php?post=41&action=edit indicates that the ID of the post or page you want to reference is 41.

Why is the anchor link not working?
The anchor link relies on the ID that WordPress automatically generates when you insert an image with a caption. If you inserted the image manually or without a caption, the anchor won’t jump you to the spot in the page. The ability to specify an anchor may be added at a later time, or you can just add the ID (attachment_##) to the img tag.

I selected a registered size but the images are showing up huge or in the wrong size.
The images may be missing the thumbnails of that size and by default will pull the full size image instead. Try using Viper007Bond’s fantastic Regenerate Thumbnails plugin to create new versions for any new or changed image sizes.

Screenshots

Really Simple Gallery Widget options
Widget options
Sample display with prefixed title showing
Sample display with prefixed title showing

Changelog

1.0

  • First version
Really Simple Gallery Widget

29 thoughts on “Really Simple Gallery Widget

  1. mann says:

    Hellow,

    Your creation is really nice,
    But unfortunately its not useful for me because I am using external image links in my posts.

    Is it possible that it will work on external image links or it would catch very first image url link from any post ????

    you can work on it.
    waiting for a favorable action

    mann

    Like

  2. Thank you for your plugin. I really love the Really Simple Gallery Widget you have created. That’s exactly what I want and it’s really SIMPLE to use. Great job!!! Thank you very much!

    Like

  3. Thank you for this plugin. I like how it lets me to choose which image from post I like to be shown and set link rel attribute. It works well, but is there any posibility to switch from choosing one post to whole category of posts?

    Like

    1. Helen says:

      I don’t have plans to add category selection at this time, unfortunately. I will add this to the list of things to think on for the future!

      Like

  4. I installed the plugin. I put the widget in the right side bar (I can see it in my page). I created a page (id=154). I pasted one photo in that page (right clic, paste)
    I putted the number 154 In “page or post ID” of the widget, and nothing happened. I can see the widget with is title (“Ils nous soutiennent”) but No photos at all…

    Like

  5. Helen says:

    Images need to be attached to the page in order for the widget to know to grab them. Copy-pasting them does not actually add it to your own site. The easiest way to attach an image is to save it to your computer and then upload it and insert it when editing the page.

    Like

  6. Michael says:

    Thanks for this plugin. There are a few different plugins that offer similar functionality, but I think this one is most to my liking.

    I’m happy I had a look around to see if a plugin existed to do this, saves me writing one myself.

    Like

    1. Helen says:

      I’m glad it works for you – I wrote this specifically because there wasn’t one that filled my need, so it’s great to know it works for others as well. Please let me know if there’s anything you’d like to see it do!

      Like

  7. Hi. In order to respect the menu_order setting (the given order that the user chooses in the media administration interface), You might want to add to the file widget.php, lines 26 and 58 the following option:

    ‘orderby’ => ‘menu_order’,

    Thanks, your plugin is awesome!

    Like

  8. sorry i only added the code avobe in line 58, since it only applies for current post/page only. (line 26 was for ‘all images’).

    Another trick i implemented was to add the featured image (post thumbnail) when the post/page doesn’t have attached images but it choosed an image from the gallery as a featured image/thumbnail.

    I solved this by adding the following code to widget.php, line 82 (if $attachments is empty)


    elseif (has_post_thumbnail($post_id)) {
    $id = get_post_thumbnail_id($post_id);
    $attachment = get_post($id);
    $image = wp_get_attachment_image_src($id, $image_size);
    $image['ID'] = $id;
    $image['title'] = $attachment->post_title;
    $images[] = $image;
    }

    Thanks again!

    Like

    1. Helen says:

      Oops, I missed your comments somehow! That’s what I get for getting so far behind. Thanks for the hint about menu_order, I actually only discovered that you could sort things in the gallery very recently. I’ll add and test that soon.

      I like the idea of also pulling in a featured image even if it’s not attached, but I’m trying to stick to this being “really simple” and just using the built-in gallery, at least by default. I wonder if I should start thinking on some hooks (actually, I’m already thinking of a couple) so you don’t have to modify the plugin code itself to get it to do what you want. Food for thought 🙂

      Like

    1. Helen says:

      Can you tell me what kind of lightbox you’re using? Most lightbox scripts use the format `lightbox[gallery]` for the `rel` attribute. The word lightbox should be whatever the script you’re using uses, and gallery can be whatever you want it to be. Let me know if that solves the issue.

      Like

    1. Helen says:

      This might not be the right plugin for that, at least at the moment. It’s using built-in attachment (gallery) functionality, which isn’t really about external links. I have a list of hooks I want to add to the plugin at some point, so perhaps the link URL would be something to filter.

      Like

  9. Hi Helen,
    thansk for the great plugin. I love it!
    Is there any way to exclude certain images from my media library to be shown in the random images?
    Would love to have that option.
    Cheers
    Sascha

    Like

  10. Peter says:

    I just installed your plugin and it is exactly what I needed. Thank you!

    Is there a way to somehow exclude images which are already displayed in the post? For example: I have 10 images uploaded to a post or page and two of those are included within the text. At the moment your plugin lists all images associated with the post or page. Could you somehow offer an option in the widget to exclude already disaplayed photos?

    Thanks!
    Peter

    Like

    1. There’s no good/completely reliable way to detect what images are actually displayed in the post, so I’m not sure I could create a solution that applies universally, and I’m also loathe to add more options (also applies to your other comment). There are some filters now in 1.2 that might be able to help you with the exclusion part, and I’ll have to think about what could help with the no images case.

      Like

    1. Peter says:

      I was actually able to hide the title when there are no images by editing the widget.php file:

      delete the 5th line: if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }

      and insert this part: echo $before_title . $title . $after_title;
      after line 84: if ( !empty($images) ) {

      Works perfectly!

      Like

Leave a comment