I have several images attached to each post. I need to generate a gallery, but because it's heavily customized I don't want to use a gallery plugin, nor the gallery short code. It's also situated in a DIV that is totally separated from the post content/title etc. so it has to be stand-alone code in PHP, hard-coded.

Basically if there's a method to retrieve the list of attachments in a URL format.. and then pull in the proper sizes (filename_80X80.jpg or something along those lines - I know the filenames are manipulated after the thumbnail size).

I already have the thumbnail sizes covered using

add_image_size( 'ourwork_full', 589, 315, true );
add_image_size( 'ourwork_thumb', 80, 80, true );

in the funtions.php file of the template.

How can I achieve this? Do I need to use custom WP query? Or is there a function/template tag that I am missing?

1 Answer 1


Query for image attachments would be something like this (taken from Get The Image plugin/extension) with get_children():

$attachments = get_children( array( 
    'post_parent' => $args['post_id'], 
    'post_status' => 'inherit', 
    'post_type' => 'attachment', 
    'post_mime_type' => 'image', 
    'order' => 'ASC', 
    'orderby' => 'menu_order ID' 
) );

Then you can loop through array and retrieve URLs with wp_get_attachment_image_src() which will get you URL and dimensions.

  • Managed to take this and create a custom function just for me.. thanks again, fantastic stuff.
    – jeffkee
    Commented Jan 19, 2011 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.