Get Attached Images from Post on Wordpress


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php function postimage($size=thumbnail, $qty=-1) {
  2. if ( $images = get_children(array(
  3. 'post_parent' => get_the_ID(),
  4. 'post_type' => 'attachment',
  5. 'numberposts' => $qty,
  6. 'post_mime_type' => 'image',)))
  7. {
  8. foreach( $images as $image ) {
  9. $attachmenturl=wp_get_attachment_url($image->ID);
  10. $attachmentimage=wp_get_attachment_image( $image->ID, $size );
  11.  
  12. echo '<li><a href="'.$attachmenturl.'" rel="shadowbox[photos]">'.$attachmentimage.'</a></li>' . "\n";
  13. }
  14. } else {
  15. echo "No Image";
  16. }
  17. } ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.