Get all attached images for a wordpress post/page


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

Short php snippit to get all images that are attached to a post or page in wordpress.
Need to mod to only get gallery images.


Copy this code and paste it in your HTML
  1. <?php
  2. $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' =>'image') );
  3. foreach ( $attachments as $attachment_id => $attachment ) {
  4. echo wp_get_attachment_image( $attachment_id, 'medium' );
  5. }
  6. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.