Title: Attachments plugin sample code (Jonathan Christoper)
Last modified: August 19, 2016

---

# Attachments plugin sample code (Jonathan Christoper)

 *  [sunriseweb](https://wordpress.org/support/users/sunriseweb/)
 * (@sunriseweb)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/attachments-plugin-sample-code-jonathan-christoper/)
 * Hi,
    Just wanted to say thanks to Jonathan Christopher for the attachments plugin.
   I’m sort of wondering why non-image attachments just don’t show up with their
   associated icons when inserting [gallery] in a post/page but the Attachments 
   plugin does the trick!
 * Some suggestions:
    i) Pull the title and caption from the (and description) entered
   in the standard WP Media as the default for the attachments array.
 * ii) Also allow re-ordering by putting in an integer field like in the WP standard
   media gallery functionality. The drag and drop re-ordering is awesome but cumbersome
   when there are a large number of attachments.
 * Here is some code I added to my template to display the attachments with the 
   Media title – note that I get the filename but then I decided not to use it. 
   I added this in immediately after the_content(). Thought someone might find this
   useful.
 *     ```
       <?php the_content(); ?>
       <!-- list attachments in post -->
       <div id="attachments">
                   <?php
                     $attachments = attachments_get_attachments();
                     $total_attachments = count($attachments);
                   ?>
                   <?php if( $total_attachments > 0 ) : ?>
   
                       <?php for ($i=0; $i < $total_attachments; $i++) : ?>
                         <div class="attachments-div">
                           <?php
                             $tmp_attachment_id = $attachments[$i]['id'];
                             $tmp_post_id = get_post($tmp_attachment_id);
                             $tmp_title = $tmp_post_id->post_title;
   
                             $tmp_path_array = explode("/",$attachments[$i]['location']);
                             $tmp_array_length = sizeof($tmp_path_array)-1;
                             $tmp_filename = $tmp_path_array[$tmp_array_length];
                             $j=$i+1;
                           ?>
                           <a href="<?=$attachments[$i]['location']?>" alt="<?=$tmp_title?>" title="<?=$tmp_title?>" target="_blank">
                           <?php
                             echo "<p>$j) <b>$tmp_title</b></p>";
                           ?>
                           <p>
                               <?php
                                 echo wp_get_attachment_image($attachments[$i]['id'], $size='thumbnail', $icon = true);
                               ?>
                           </p>
                           </a>
                         </div>
                       <?php endfor ?>
   
                   <?php endif ?>
                 </div>
       ```
   
 * The associated CSS is:
 *     ```
       #attachments {
         margin: 2em;
       }
       .attachments-div {
         position: relative;
         float: left;
         padding: 5px;
         margin: 5px;
         border: 1px solid #000000;
         text-align: center;
         width: 300px;
         height: 160px;
       }
       ```
   
 * [http://wordpress.org/extend/plugins/attachments/](http://wordpress.org/extend/plugins/attachments/)

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

 *  Thread Starter [sunriseweb](https://wordpress.org/support/users/sunriseweb/)
 * (@sunriseweb)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/attachments-plugin-sample-code-jonathan-christoper/#post-1686050)
 * Oh yes – here is a site where you can see this in action:
 * [http://huronshores.ca/2010/09/2009-minutes/](http://huronshores.ca/2010/09/2009-minutes/)
 *  Thread Starter [sunriseweb](https://wordpress.org/support/users/sunriseweb/)
 * (@sunriseweb)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/attachments-plugin-sample-code-jonathan-christoper/#post-1686051)

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

The topic ‘Attachments plugin sample code (Jonathan Christoper)’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/attachments_fafafa.svg)
 * [Attachments](https://wordpress.org/plugins/attachments/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/attachments/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/attachments/)
 * [Active Topics](https://wordpress.org/support/plugin/attachments/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/attachments/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/attachments/reviews/)

 * 2 replies
 * 1 participant
 * Last reply from: [sunriseweb](https://wordpress.org/support/users/sunriseweb/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/attachments-plugin-sample-code-jonathan-christoper/#post-1686051)
 * Status: not a support question