Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following code (see below) that lists all attached images from a post. I'm trying to alter this code to only list the first five images, and also to exclude the featured image from the list. Any help is certainly appreciated. Thanks in advance.

<div class="entry-content">
<ul>
    <?php 

     $args = array(
       'post_type' => 'attachment',
       'numberposts' => -1,
       'post_status' => null,
       'post_parent' => $post->ID
      );

      $attachments = get_posts( $args );
         if ( $attachments ) {
            foreach ( $attachments as $attachment ) {
               echo '<li>';
               echo wp_get_attachment_image( $attachment->ID, 'thumbnail' );
               echo '</li>';
              }
         }
    ?>
</ul>
</div><!-- .entry-content -->
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Did you try this:

 $args = array(
   'post_type'      => 'attachment',
   'posts_per_page' => 5,
   'post_status'    => 'inherit',
   'post_parent'    => $post->ID,
   'exclude'        => get_post_thumbnail_id( $post->ID )
  );
share|improve this answer
    
Thank you @birgire! This worked perfectly. Much appreciated. –  user1512680 Nov 22 '13 at 19:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.