Skip to content

Instantly share code, notes, and snippets.

@sagarjadhav
Created June 20, 2013 10:36
Show Gist options
  • Save sagarjadhav/5821753 to your computer and use it in GitHub Desktop.
Save sagarjadhav/5821753 to your computer and use it in GitHub Desktop.
Get WP Post Attachments
<?php
/* Get Children Images */
function rtp_get_post_attachments( $parent_id ) {
$args = array(
'post_type' => 'attachment',
'numberposts' => 3,
'post_status' => null,
'post_parent' => $parent_id,
'exclude' => get_post_thumbnail_id($parent_id)
);
$attachments = get_posts( $args );
if ( $attachments ) { ?>
<div class="rtp-attachment-container"><?php
foreach ( $attachments as $attachment ) {
$img_id = $attachment->ID;
$img_title = $attachment->post_title;
$img_src = wp_get_attachment_image_src($img_id, 'thumbnail');
echo '<img src="' . $img_src[0] . '" class="" alt="'. $img_title .'" />';
} ?>
</div><?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment