labcoatmedia

WP: Grab image attachments from current post and display

Jul 19th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  2.     <?php $query_images_args = array(
  3.         'post_type' => 'attachment',
  4.         'post_mime_type' =>'image',
  5.         'post_status' => 'inherit',
  6.         'post_parent' => $post->ID,
  7.         'posts_per_page' => -1
  8.         );
  9.    
  10.         $query_images = new WP_Query( $query_images_args );
  11.         $images = array();
  12.         foreach ( $query_images->posts as $image) { $images[]= $image->guid; };
  13.     ?>
  14.  
  15.     <img src="<?php echo $images['0']; ?>" alt="" />
  16.  
  17. <?php endwhile; endif;?>
Advertisement
Add Comment
Please, Sign In to add comment