Skip to content

Instantly share code, notes, and snippets.

@brunomonteiro3
Created October 20, 2015 13:02
Show Gist options
  • Save brunomonteiro3/67ac0b50855517aade4e to your computer and use it in GitHub Desktop.
Save brunomonteiro3/67ac0b50855517aade4e to your computer and use it in GitHub Desktop.
List all attachments of a post or page in Wordpress.
<?php
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id(),
'orderby' => 'menu_order',
'order' => 'ASC'
) );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );
$thumbimg = wp_get_attachment_image_src( $attachment->ID, 'full');
?>
<li><img src="<?php echo $thumbimg[0]; ?>" /></li>
<?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment