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 shortcode 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. Once you’ve done that you can use the function insert_recent_images_box in your theme or the shortcode [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() {
  # add all the conditional tags you're using to the array
  if (assert_functions_exist(array('is_front_page')) === false)
    return false;
 
  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:

<?php insert_recent_images_box(2); ?>

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

Using the widget

Instead of inserting a function call into your theme you can use the widget. Function call or widget – it’s as easy as that.

Using the shortcode

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

[recent-images-box]

This 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.

9 comments ↓

  • Thanks Christian. I’ll give this a shot. :)
  • boylogik says:
    FYI – I downloaded the latest plugin from wp today. The config.php file in there does NOT have the following text anywhere – - – -
    ENABLE_RECENT_IMAGES_BOX_FILTER. It has the -ENABLE_RECENT_IMAGES_BOX, but NOT the _FILTER statement.

    Also, I read above that if we use it inside our theme just for the home page, we should update the function to — if (is_front_page()) { etc —- BUT, if we use the ‘front_page’, don’t we have to change the line above it to also reference front_page – - – meaning — if (assert_functions_exist(array(’is_FRONT_PAGE’)) === false) return false;

    5 hours and counting…still no luck. Just want it to pull the pics from body of most recent postings.

    What am I doing wrong – need on homepage to show most recent posts:

    function insertSmoothGallery() {
    if (is_front_page()) {
    return array(’width’ => 400,
    ‘height’ => 200,
    ‘timed’ =>true,
    ‘delay’ =>2000?,
    ’showInfopane’ =>true,
    ’showArrows’ =>true,
    ‘Carousel’ =>true,
    ‘embedLinks’ =>false);
     
    }
    return false;
    }

    and then went into my index.php and inserted the following as instructed:
    insert_recent_images_box(2);

  • Hi boylogik,
    I’ve just updated the information on this page reflecting the changes I made to the plugin but forgot to update the documentation here.
    Your implementation of the insertSmoothGallery looks fine so far, but having a look at your website I saw that you just added insert_recent_images_box(2) to the HTML as is – of course this is a PHP function call and must be embedded inside the PHP tags, i.e. <?php ... ?>.
  • boylogik says:
    Thanks Christian – I made the necessary adjustments. Thx for catching that. Unfortunately, still not working. I’ll continue trying.
  • Yelle says:
    Hi Christian! I’m trying to figure out how to put the SmoothGallery into the banner of OpenBook theme. Any help would be very welcome. Thank you!
  • Hi Yelle,
    the OpenBook theme already has a SmoothGallery and you don’t necessarily need this plugin. Read the instructions here under Configuring SmoothGallery and learn how to fill the gallery with images.
  • Yelle says:
    Thanks for the link, Christian! Will try to work it out. :-) I’m quite the newbie, so thanks for your patience.
  • Amr Darwish says:
    i got this error

    Warning: require_once(../utils.php) [function.require-once]: failed to open stream: No such file or directory in /home/content/a/m/r/amrdarwish/html/v2wp/wp-content/plugins/smoothgallery/extra/recent_images_box.php on line 54

    Fatal error: require_once() [function.require]: Failed opening required ‘../utils.php’ (include_path=’.:/usr/local/php5/lib/php’) in /home/content/a/m/r/amrdarwish/html/v2wp/wp-content/plugins/smoothgallery/extra/recent_images_box.php on line 54

  • Joe Streno says:
    I am in the process of redesigning my blog. I am customizing the WordPress Christmas Theme (minus the MooTools features built in.)

    What I’d really love to be able to do is use SmoothGallery in the header so it shows up on every page, then direct SmoothGallery to use an image in a custom field with the images URL as the field’s content. And if they click on that header image, go to that page.

    I’ve tried everything, on this HowTo page … but can’t get SmoothGallery to work at all.

    If you go to my current blog … I’m using another WP theme. The Christmas Theme I’m working on a localhost server & it is not yet active.

    Any help you can give would be appreciated.

    Thanks … Joe