seeing

a
later
date

new gallery feature in WordPress 2.5

web, tech & gadgets

When I saw the new image and media management built right into the new WordPress 2.5, I was very excited. It seems a lot easier, at least on the face of it. One problem, however, is that there’s precious little documentation on how to use the new features. For example, it took me forever to figure out how to get the nice thumbnail prev-next navigation that Matt shows on his blog. So here’s a quick tip for theme developers trying to use the new gallery feature:

You’ve got a new template you can use: image.php (yee ha!) The new gallery feature seems to set up ’sub-posts’ for each of the images attached to a post or page. If there is no image.php in your theme, it will use the single.php template (best as I can tell, anyway) to display them. But you can create this image.php template and use new template tags to display the thumbnail navigation if you wish. (You can also change the layout or whatever else you’d like as well, of course.)

The new thumbnail navigation template tags:
previous_image_link() and next_image_link()

Include these in your image.php template file the way you would normally include template tags. Check the Default theme that’s bundled with the new 2.5 install to see how it’s done there. You also have to deal with new template tags like:

wp_get_attachment_image() and wp_get_attachment_url()

Again, the only existing documentation seems to be the image.php file itself in the new version of the Default theme.

tagging:

categorizing: web, tech & gadgets

You can make a comment below or link a trackback from your own site. RSS feed for comments on this post.

commenting:

  1. How do Shortcodes come into this (if at all)?

    Comment by logista — March 30, 2008 @ 9:28 am
  2. The gallery thing has a shortcode, and that’s how you put it into a post or page. So in practice, [gallery] is just a call to a function that grabs all the image attachments to a post and displays them. So the [gallery] shortcode is a use of the Shortcode API.

    This post has more to do with theme development and the new tags available to display image attachments. This idea of attachments to posts is new to WP. It allows for cool things like this new gallery display, but it requires a new template if you want to fully take advantage of it.

    The Shortcode API is mostly of interest to plugin developers, I think. It’s a quick and easy way to have plugin users inject your plugin output into a post or page.

    Comment by mitten — March 30, 2008 @ 9:56 am
  3. [...] bit of sleuthing revealed the solutions. I found out that the individual image gallery pages look for an image.php template.  Also, these pages use the [...]

  4. Is there some special magic needed to get wp_get_attachment_image() to work? Because I cannot get it to fire to save my life!

    Comment by Sean — March 30, 2008 @ 7:12 pm
  5. If you don’t have image.php, the gallery falls back to single.php. Without single.php, the gallery uses index.php. The function tags are sane.

    I’m ambivalent about the gallery, though. The controls for it are fantastic, but the presentation is not so much. I need the time to write a plugin to make what I want of it; template hacking only goes so far.

    Comment by Art — March 31, 2008 @ 8:37 am
  6. Sean - I’m not sure what to tell you except to copy from the image.php that comes with the Default theme. You might be able to cull some more information from this thread on the forums, too: http://wordpress.org/support/topic/164216

    Art - it feels not ready for prime time to me. I like the ease of uploading images, but if a newbie can’t use the gallery part of it out of the box, then it seems a bit unfair to flaunt it as one of the big new features.

    Comment by mitten — March 31, 2008 @ 6:57 pm
  7. Thank you for this - you saved my sanity.

    Comment by Fuzz Martin — April 1, 2008 @ 4:37 am
  8. hi, this is actually very helpful, thanks a lot :)

    Comment by Ivette — April 2, 2008 @ 11:04 am
  9. [...] deeper search revealed that the gallery feature relies not only on the new uploader, but also on a new template [...]

  10. Thanks so much for this post! I was able to copy the new image.php and hack away until it suited me fine — only took about 20 minutes to incorporate into the theme I’ve adapted, with a few changes (and also I’ve added a link back to the original post under the nav images).

    It’s only a very new site and has lots to be developed (only started work on this last night), but it’s at africanimpact.com.au if you see the blog item for Cape Town under “project updates”, you can see how I’ve administered it.

    Still 1 thing I am having trouble changing which I hope they fix: on the post sub-page, I cannot turn off comments (without hacking the image.php like I have to remove the comment facility altogether) — it should refer to the comment setting for the actual (parent) post, but it doesn’t seem to.

    Anyway, your article helped me getting it working, albeit with a fair bit of work to the default image.php. Thanks so much!

    Comment by Dean — April 14, 2008 @ 3:28 pm
  11. [...] a post outlining some of the basic functions of the new template option over at Laura Fisher’s blog, and there’s a little bit of information about the gallery shortcodes in the WordPress [...]

  12. [...] and next image and link as you navigate through the photos in your gallery post. Hat tip to mitten. I should apply this to my first and only (so far) gallery post I created a month ago. [...]

    Pingback by WordPress Gallery Feature | Deuts.NET — June 24, 2008 @ 10:33 am

being

This is Laura Fisher's blog, coming to you from Ann Arbor, Michigan. You might know me as mitten and you can find me in many online communities under that name. Comments are welcome here, or you can write to me more privately via the contact form.

searching

Lijit Search

reviewing

speed racer

Forget the old cartoon, forget any hint of serious intent and go watch this movie for the sheer technicolor delight of it. It's beautiful, it's fast, it's silly (in the good way), it's exciting and inspired. Go Speed go!

twittering

@vaguery Thanks! See you all in a week. 5 days ago

noting

friends are saying

  • Derek Mehraban
  • Ann Arbor is Overrated
  • murph
  • Arblogger

listening

attending


recommending

sharing