Title: Weird (?) problem
Last modified: August 22, 2016

---

# Weird (?) problem

 *  Resolved [96dpi](https://wordpress.org/support/users/96dpi/)
 * (@96dpi)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/weird-problem-12/)
 * When trying to insert the attachments list into my theme, I get this output:
 *     ```
       <h3>Attachments</h3>
                           <ul>
                               <li>
                                   <pre>stdClass Object ( [id] => 190 [fields] => stdClass Object ( [title]
                                       => Test title [caption] =>
                                       <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius
                                           enim in eros elementum tristique. Duis cursus, mi quis viverra ornare,
                                           eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus
                                           nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus
                                           tristique posuere.</p>) [post_id] => 10 )</pre>
                               </li>
                           </ul>
       ```
   
 * So I get the correct attachment and all, but something isn’t working like it 
   should.
 * BTW. I’m trying to use it on a page, not a post.
 * [https://wordpress.org/plugins/attachments/](https://wordpress.org/plugins/attachments/)

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

 *  Thread Starter [96dpi](https://wordpress.org/support/users/96dpi/)
 * (@96dpi)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/weird-problem-12/#post-5231917)
 * Oh ok.
 * The instructions are way too fuzzy for non-coders like me. I tried to use the
   code from the instructions under “Pulling Attachments to your Theme”:
 *     ```
       <pre><?php print_r( $attachment ); ?></pre>
       ```
   
 * …but this only displays the attributes followed by their value.
 * The right way to do this is to follow the instructions under [Retrieve Attachment Attributes](https://github.com/jchristopher/attachments/blob/master/docs/usage.md#retrieve-attachment-attributes).
   E.g. use
 *     ```
       <?php echo $attachments->field( 'title' ); ?>
       <?php echo $attachments->field( 'caption' ); ?>
       ```
   
 * etc.
 * 🙂
 *  Thread Starter [96dpi](https://wordpress.org/support/users/96dpi/)
 * (@96dpi)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/weird-problem-12/#post-5231924)
 * Also, if anyone would like to add their attachments with a shortcode, try this:
 *     ```
       function list_publication_attachments( $atts ) {
   
         ob_start(); ?>
   
         <?php $attachments = new Attachments( 'attachments' ); /* pass the instance name */ ?>
         <?php if( $attachments->exist() ) : ?>
           <div>
             <?php while( $attachment = $attachments->get() ) : ?>
               <?php echo $attachments->image( 'thumbnail' ); ?>
               <h3><a href="<?php echo $attachments->url(); ?>"><?php echo $attachments->field( 'title' ); ?></a></h3>
               <p><?php echo $attachments->field( 'caption' ); ?></p>
             <?php endwhile; ?>
           </div>
         <?php endif; ?>
   
         <?php
           $sc = ob_get_contents();
           ob_end_clean();
           return $sc;
       }
       add_shortcode('publications', 'list_publication_attachments');
       ```
   
 * Add it to `functions.php` or in a file called `shortcodes.php` and include it
   in `functions.php` with
 *     ```
       include('shortcodes.php');
       ```
   
 * This will let you add the list of attachments by using _[publications]_ as a 
   shortcode in any WP-post/page.
 * Happy coding!

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

The topic ‘Weird (?) problem’ 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/)

## Tags

 * [attributes](https://wordpress.org/support/topic-tag/attributes/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 2 replies
 * 1 participant
 * Last reply from: [96dpi](https://wordpress.org/support/users/96dpi/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/weird-problem-12/#post-5231924)
 * Status: resolved