Displaying Multiple Post Images With The Attached Image

/ Wordpress / by Paul Robinson / 2 Comments
This post was published back on December 3, 2009 and may be outdated. Please use caution when following older tutorials or using older code. After reading be sure to check for newer procedures or updates to code.

@nomadone just asked a increadibly good question on my post for the plugin The Attached Image. This is what @nomadone said:

Thanks so much this is a really great plugin. I’d say it would be even greater if you could use multiple template tags to pull say first image 1 in the gallery order and display it large and then another to display image 2 medium sized etc. Custom fields get a bit laborious when it comes to that kind of setup. Thanks for all your hard work and contribution to help make our lives easier with this great plugin!

What @nomadone asked for is entirely possible, but I’ve just realized that it isn’t exactly made clear by the documentation I’ve provided. So I’ve decided to make this little post to explain to those who don’t read the post comments.

To do it you use the image_order parameter. This is inside your template with a template call (not custom fields, or admin). First find the spot for your first image & place this code:

Replacing img_size=large for whatever size image you want to be displayed, you can also apply any of the legacy options you want. To show the second image use the following:

Again change the image size if you like. How does it work? Well it uses the image_order parameter which tells The Attached Image to get the second image attached to the post (using the uploaders gallery to determine the order). You can use the image_order parameter to get the (n)th image, meaning the image defined by the number given. If no image of that number exists it will fall back to the nearest image it can get, so if you ask for image 5 & only 3 exist it will go for the 3rd one.

I hope that helps everyone. If you have any problems or would like to suggest a tutorial (as I’m looking for ideas) drop me a comment or send me an email using the contact form. 🙂

2 Comments

Author’s gravatar

Hey paul

I love your plugin but how do I make this so if there is no second or third image it shows nothing?

Some of my posts have the images and some dont and I want it to be blank if it cant find the second or third image

Thanks heaps

Andy

Reply
Author’s gravatar author

If there is no image the attached image should return blank (unless you have a default image set).

If you can tell me what it is giving you instead of blank I’ll see if I can find a solution for you. 😉

Older Comments
Newer Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

I'll keep your WordPress site up-to-date and working to its best.

Find out more