Created
June 20, 2013 10:36
-
-
Save sagarjadhav/5821753 to your computer and use it in GitHub Desktop.
Get WP Post Attachments
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 | |
/* 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