Created
October 20, 2015 13:02
-
-
Save brunomonteiro3/67ac0b50855517aade4e to your computer and use it in GitHub Desktop.
List all attachments of a post or page 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 | |
$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