How do i show wordpress attachments from current post?

So with my blog i have a photo attachment page but it only shows to photo’s at a time, and those two photo’s are used as the navigation and i hate that.

I want the attachment page to show all the photo’s that goes along with the rest of that set.

Read More

Here is the current code

        <div id="nav-images" class="navigation clearfix">
            <div class="nav-next"><?php next_image_link() ?></div>
            <div class="nav-previous"><?php previous_image_link() ?></div>

How do i change that to show all the post attachments?

Related posts

Leave a Reply

2 comments

  1. Your code and description seem to refer to the previous/next attachment navigation. That code is intended to display previous/next attachment navigation, and that’s exactly what it’s doing.

    If you want to display all attachments:

    1. Within the Post Content, use the [gallery] shortcode
    2. Programmatically, in the template file, use e.g. get_posts(), combined with e.g. wp_get_attachment_image():

      <?php
      global $post;
      $attachment_images = get_posts(
          'post_type' => 'attachment',
          'post_parent' => $post->post_parent,
          'post_mime_type' => 'image'
      );
      // Output images
      ?>
      <ul>
      <?php
      foreach ( $attachment_images as $attachment_image ) {
          // Output images here. Note that get_posts()
          // returns an array of OBJECTS, so the ID
          // would be $attachment_image->ID
          echo '<li>' . wp_get_attachment_image( $attachment_image->ID, 'thumbnail' ) . '</li>';
      }
      ?>
      </ul>
      
  2. Hi Chip, Unfortunately that didn’t work, but I finally found it after hours and hours of searching.

    First you have to add the below code to the functions.php file

    function show_all_thumbs() {
        global $post;
        $post = get_post($post);
        /* image code */
        $images =& get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->post_parent);
        if($images){
            foreach( $images as $imageID => $imagePost ){
                unset($the_b_img);
                $the_b_img = wp_get_attachment_image($imageID, 'thumbnail', false);
                $thumblist .= '<a href="'.get_attachment_link($imageID).'">'.$the_b_img.'</a>';
            }
        }
        return $thumblist;
    }
    

    and then add the below code to where you want the thumbnails to show.

    <?php echo show_all_thumbs();?>
    

    Sorry I don’t know how to put the whole code in the box so i had to jam toegether every line 🙁