Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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."' />';
}
share|improve this answer
    
Brilliant, thank you! This worked, and in conjunction with a custom short tag does exactly what I need. –  Pekka 웃 Sep 18 '11 at 14:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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