mf_gallery_shortcode()

Wordpress 2.5 offers a great feature for adding an image gallery to posts: the shortcode. There’s only one problem, how do you control exactly which images are displayed in the gallery? The answer…. “well, you can’t really”. I really wanted to be able to specify the images for each gallery, so I took some time to write the following simple plugin which adds a new parameter to the original.

Download mf_gallery_shortcode() v0.1.2
Download mf_gallery_shortcode() v0.1.1
Download mf_gallery_shortcode() v0.1

Installation

  1. Extract the zip file locally.
  2. Upload mf_gallery_shortcode.php to your /wp-content/plugins/ directory.
  3. Activate the plugin through the “Plugins” menu in WordPress.

Define Attachments to be Included

Insert the following code into your post’s content field specifying the attachments that you want to be displayed as a comma separated list of attachment ID’s. This parameter allows you to add only the attachments that you want displayed in each gallery. Note: attachments do not have to be children of the current page or post to be used here.

 
[gallery include="1,2,3,4"]

Define Attachments to be Excluded

Insert the following code into your post’s content field specifying the attachments that you do not want to be displayed as a comma separated list of attachment ID’s. All attachments that are children of the current page or post will be displayed except for the ones defined in the list.

 
[gallery exclude="1,2,3,4"]

Version info

This plugin will only work with Wordpress version 2.5.

Notes

Version 0.1.2

  1. The attribute ‘ids’ has been depreciated. It it still supported for backward compatibility.
  2. All attachments link directly to themselves, bypassing attachment.php or any of its derivatives (image.php, pdf.php, etc…) There is no easy way to link to the attachment page while retaining the ’set’ of images defined by “include” or exclude parameters. If you have any ideas how this might be circumvented, please leave a comment below.

License

GNU General Public License

Comments

3 Responses to “mf_gallery_shortcode()”

  1. Lara on May 4th, 2008 5:55 am

    Is there a version of this that would work in EXCLUDING an image?

    Example, I have written a post that has 12 images I want in the gallery, and one which I want to use later in the post, NOT in the gallery. Rather than having to include the id numbers for 12 images, it’d be much easier to exclude just one id number…

    Please email me if you get this to work, and great job on the plugin!

  2. M3g on June 2nd, 2008 12:35 am

    I tried all 3 versions on this page, none of them works, i tried the v0.1 and when I use [gallery ids="1,2,3,4"] in the post, it shows “Missing attachment’, when I tried the v0.1.1, when I use [gallery ids="1,2,3,4"], it shows nothing and if I use [gallery] in the post, it shows just images without links, when I tried v0.1.2, I insert [gallery include="1,2,3,4"] in the post, it just shows some post titles and they all link to the same page I am viewing. O.O I’m wondering what is wrong

  3. Neil on June 6th, 2008 2:08 pm

    I really like this function but conflicts with Cleaner Wordpress Gallery . Maybe you guys should work together. :)

Leave a Reply