1

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.

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?

2 Answers 2

4

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, That post does code does not work, is there another one Feb 27, 2012 at 20:27
  • You've not provided nearly enough information for me to answer your question any more accurately. I don't know what exactly you tried, where you put the code, or what the output was. Feb 28, 2012 at 1:53
1

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 :(

1
  • 3
    I'm glad you found a working solution, but you're doing almost exactly what I suggested. :) Feb 28, 2012 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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