Skip to content

Instantly share code, notes, and snippets.

@tommaitland
Created August 12, 2013 10:42
Show Gist options
  • Save tommaitland/6209835 to your computer and use it in GitHub Desktop.
Save tommaitland/6209835 to your computer and use it in GitHub Desktop.
Display all images attached to a post in WordPress (http://tommaitland.net/2012/10/display-all-images-attached-to-a-post-in-wordpress/)
<?php
$gallery = get_children( 'posts_per_page=5&post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
$attr = array(
'class' => "attachment-$size wp-post-image",
);
foreach( $gallery as $image ) {
echo '<a href="' . wp_get_attachment_url($image->ID) . '" rel="gallery-' . get_the_ID() . '">';
echo wp_get_attachment_image($image->ID, 'thumbnail', false, $attr);
echo '</a>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment