I know a lot of people have seen the custom attachment templates that are used by loads of people on Wordpress blogs, for example Matt Mullenweg, and myself. Recently, I’ve seen a lot of stuff asking how to do it, especially for images, thanks to the new feature in WP2.5, which gives sub-pages for images.
Ordinarially, Wordpress uses the post.php or index.php file from your theme directory for the image template, which just formats it exactly like any other post you can find. However, if you put in a file called attachement.php, it’ll work from that whenever it finds an attachment - this is the Wordpress theme hierarchy.
To make your own attachment template, take the contents of your post.php file and make a new file called attachement.php - then modify the layout to exactly how you want it. That part is simple.
Problem is that Wordpress doesn’t show the image as part of the_content() in the template anymore, so you need to find it manually. Never fear, however, because this is really simple. If you put this code in where you want your image to be:
<?php echo wp_get_attachment_image( $post->ID, 'medium' ); ?>
Then it’ll show up. Obviously, if you change ‘medium’ to ‘large’, you’ll get the full size image and so on. Then you can move the
<?php the_content();?>
to wherever you want the image caption to be, because that’s all that will be there. It’s awesomely simple. You can also link to the full size image using a bit of code like this:
You can see the full size image <a href="<?php echo wp_get_attachment_url($post->ID); ?>">here</a>
Nice and simple. Now, upload the file into your themes directory, and voila!
Popularity: 54% [?]


