Recent images box


If you’d like to aggregate the images from your most recent posts into one gallery you’ll like this feature. All you have to do is to use WordPress’ built-in Media library to attach images to your posts, call a function somewhere inside your theme or use a special tag inside your post and the plugin picks up these images and generates the gallery for you.

Howto

If you’d like to enable this feature, open the file config.php in an editor and change the value of ENABLE_RECENT_IMAGES_BOX to true. If you plan to use this feature inside the content of a post or a page change the value of ENABLE_RECENT_IMAGES_BOX_FILTER to true too.

Once you’ve done that you can use the function insert_recent_images_box in your theme or the special tag <!--recent-images-box--> inside the content of a post or a page.

Using the function

You’ll have to call the function insert_recent_images_box somewhere inside your theme and implement the function insertSmoothGallery; the latter makes sure that the CSS and JavaScript will be included along with the gallery.

Say, you’d like to add a 240×120 gallery to the front page of your blog and put the images of the two most recent posts into it. You’ll open the config.php and add the following to the insertSmoothGallery function:

function insertSmoothGallery() {
  if (is_front_page()) {
    return array('width' => 240,
                 'height' => 120,
                 'timed' => 'true',
                 'showInfopane' => 'false',
                 'showArrows' => 'false',
                 'embedLinks' => 'false');
  }
  return false;
}

Notice the Conditional Tag in the if statement; adapt this to your needs. Then you’ll put the following line somewhere inside your theme:

insert_recent_images_box(2);

Since 3 is the default we had to supply a parameter (2) to this function.

Using the tag inside the content

This is as easy as putting the following comment inside a post/page:

<!--recent-images-box-->

The comment gets replaced with the gallery. Don’t forget to add a custom field named smoothgallery to the post/page - this makes sure that the CSS and JavaScript will be included in the post/page.

Future work

The tag that may be used inside the content of a post/page could be changed to use the Shortcode API. Although an HTML comment has the great advantage of being invisible if something didn’t work this might come in handy if we’d like to use some parameters.

One Response to “Recent images box”

  1. U.S. Common Sense says:
    May 5th, 2008 at 3:16 am

    Thanks Christian. I’ll give this a shot. :)

Leave a Reply