图像在单独的页面中与底部的其他图像

On some sites, if you click an image within a post, you will get the image in a new page with the images in the post at the bottom. How do I replicate this behavior?

I have this code but I don't know whether it is correct or not. I don't even know where to add this. Can anyone help to explain where to add exactly?

$attachments = get_children(array('post_parent' => $post->ID,
                        'post_status' => 'inherit',
                        'post_type' => 'attachment',
                        'post_mime_type' => 'image',
                        'order' => 'ASC',
                        'orderby' => 'menu_order ID'));

foreach($attachments as $att_id => $attachment) {
    $full_img_url = wp_get_attachment_url($attachment->ID);
    // Your Code here
}

What you're describing is default feature for "galleries" of e.g. the twentyten default theme (given that I don't misunderstand you). In or around line 58 of the loop.php file you'll find:

<?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?>

The code after that should give you a hint on how to accomplish the mentioned look.

When adding an image to a post, WP will usually wrap it into a link for you, pointing at exactly this type of representation.