I am building a blog where the posts of a certain category make up image galleries (using the standard WP functionality and a modified single.php to display the gallery.)

Now, I would like to add links to some of those galleries inside other blog posts. The ideal way would be a shortcode like

[thumbnails galleryid=209]

(or whatever) that displays a definable number of thumbnails from post no. 209, and links there.

Does anybody know of a ready-made plugin that does this?

1 Answer 1


I don't think so, but you could use get_children and get the attachment(s) of those posts:

$attachments = get_children(array(
  'post_parent'     => $post->ID, // <- source post
  'post_status'     => 'inherit',
  'post_type'       => 'attachment',
  'post_mime_type'  => 'image',
  'order'           => 'post_date',
  'orderby'         => 'DESC',
  'numberposts'     => 5,         // the number

Then get the image URLs:

$size = 'post-thumbnail'; // or whatever size you need

foreach($attachments as $att){
  list($source, $width, $height) = wp_get_attachment_image_src($att->ID, $size); 
  // echo '<img src="'.$source.'" width="'.$width.'" height='".$height."' />';
  • Brilliant, thank you! This worked, and in conjunction with a custom short tag does exactly what I need.
    – Pekka
    Sep 18, 2011 at 14:59

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.