Title: Attachments?
Last modified: August 19, 2016

---

# Attachments?

 *  [Gesp](https://wordpress.org/support/users/gesp/)
 * (@gesp)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/attachments-2/)
 * Hi there,
 * I`ve got the following code:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post();?>
                  <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
               <div class="galeryColumn">
                   <?php the_content(); ?>
               </div>
           <?php endwhile; endif; ?>
           <?php edit_post_link('Edit'); ?>
       ```
   
 * How do I make the `<?php the_content(); ?>` pull only the attachments in the 
   content of the page?
 * Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/attachments-2/#post-2066366)
 * You will need to modify the Loop to use [a function such as `get_children()`](http://codex.wordpress.org/Function_Reference/get_children),
   and then output the results.
 * This function will return an array of attachment IDs, that you can use to output
   the attachments, or links to the attachments, or whatever you’re wanting to do.
 *  Thread Starter [Gesp](https://wordpress.org/support/users/gesp/)
 * (@gesp)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/attachments-2/#post-2066371)
 * Can you show me how I can do it please?
 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/attachments-2/#post-2066376)
 * Not really, without knowing exactly what you want to do.
 * Did you read the linked Codex page? It explains how to use the function in general.
 *  Thread Starter [Gesp](https://wordpress.org/support/users/gesp/)
 * (@gesp)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/attachments-2/#post-2066383)
 * I wanted to pull every attachment from a page and hang it on the masonry grid,
   but I need that code to do it. I can do it with posts because the usual loop 
   pulls the posts already.
 * I wanted a loop that only pulled the attachments.
 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/attachments-2/#post-2066387)
 * Then you want to [use something like `get_posts()`](http://codex.wordpress.org/Template_Tags/get_posts)
   to create an ad-hoc Loop. e.g.
 *     ```
       $postattachments = get_posts( array(
            'numberposts' = -1,
            'post_type' = 'attachment',
            'post_parent' = $post->ID
       ) );
       ```
   
 * This will add an array containing all of the attachments for the current post.
 * Then you need to output them:
 *     ```
       foreach ( $postattachments as $attachment ) {
            // Add your HTML markup here
            // I don't know what it is, so you'll have to figure this part out
            // However, this will output the 'thumbnail' size image:
            echo wp_get_attachment_image( $attachment->ID, 'thumbnail' );
        }
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Attachments?’ is closed to new replies.

## Tags

 * [content](https://wordpress.org/support/topic-tag/content/)
 * [images](https://wordpress.org/support/topic-tag/images/)
 * [page](https://wordpress.org/support/topic-tag/page/)
 * [post](https://wordpress.org/support/topic-tag/post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/attachments-2/#post-2066387)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
