Post Pic

Displaying Multiple Post Images With The Attached Image

@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 [...]

@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:

<?php
the_attached_image('img_size=large');
?>

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:

<?php
the_attached_image('img_size=medium&image_order=2');
?>

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. :)

Leave a Response

Please enclose code in [lang] tags. For example [php] echo 'hello world'; [/php]

* Name, Email, Comment are Required

£53.06 / £1200

Help me buy an iMac so I can develop iPhone/iPod apps. If you would like to donate, or you want to learn more about why I started this fund click here.

We're Talking About...