Support » Themes and Templates » How to display ALL images in gallery with image.php

  • Resolved Ryan Hellyer


    In the default theme, if you click on an image in a gallery, it takes you to a page generated via image.php. Do any of you know how to display the original gallery in this page?

    thanks 🙂

Viewing 13 replies - 1 through 13 (of 13 total)
  • Justin Tadlock


    WordPress God

    This should work:

    $post_parent = get_post($post->ID, ARRAY_A);
    $parent = $post_parent['post_parent'];
    $attachments = get_children("post_parent=$parent&post_type=attachment&post_mime_type=image&orderby=menu_order ASC, ID ASC");
    foreach($attachments as $id => $attachment) :
    	echo wp_get_attachment_link($id, 'thumbnail', true);

    Thanks greenshady 🙂

    Nice code, do you know how we can define the number of thumbnail per page or how to build a pagination with this code because I have more than 1000 images to display in this main gallery!

    Thanks for your help


    Anybody know how I spilt the gallery generated by this code (how to make a pagination?)

    The problem now is when someone comments on my image page, the comments do not show up! Can someone help please….

    just add

    <?php comments_template(); // Get wp-comments.php template ?>

    to your attachment.php or image.php

    l r


    This is a great fix but I want to add image.php to the thumbnails gallery default.
    So the default gallery has a single pic large image view and a gallery of thumbnails.
    Anyone know a quick fix.
    Click on thumbnail and it changes the big image on the same page.
    ( i hope this makes sense)
    Any pointers really appreciated.
    Many thanks

    Hi people,

    I tried using a different theme for my gallery in wordpress using the image.php template. What I did was copied the whole template of performancing’s photoblog from header, main index, sidebars, comments template and footer into one file and named as image.php. That’s when the problem arose about not being able to display the comments in the bottom.

    Any help is appreciated.

    anyone find a solution for pagination? Thanks

    @greenshady your code doesn’t work with wp 2.7 it only display some images which are not attach to post… Quite strange

    found a solution for WP 2.7 :

    $post_parent = get_post($post->ID, ARRAY_A);
    $parent = $post_parent['post_parent'];
    $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
    foreach($attachments as $id => $attachment) :
    	echo wp_get_attachment_link($id, 'thumbnail', true);

    using the above code crashes with Internal Error. Any idea? It doesn´t seem to have anything wrong on it…

    Just loaded GreenShady’s code for a friend and it works great.

    Using WP 2.7.1

    Check it out here.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How to display ALL images in gallery with image.php’ is closed to new replies.