Created
August 12, 2013 10:42
-
-
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/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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