where $post_id is the current post, this code will output all the attachments of a post, and their titles descriptions and captions
$q = new WP_Query( array(
'post_parent' => $post_id,
'post_type' => 'attachment'
));
if($q->have_posts()){
while($q->have_posts()){
$q->the_post();
?>
<h3><?php the_title(); ?></h3>
<?php
if ( wp_attachment_is_image( $post->id ) ) {
$att_image = wp_get_attachment_image_src( $post->id, "large");
?>
<img src="<?php echo $att_image[0];?>" width="<?php echo $att_image[1];?>" height="<?php echo $att_image[2];?>" class="attachment-large" alt="<?php $post->post_excerpt; ?>" />
<?php
}
// caption
the_excerpt();
// description
the_content();
}
}
wp_reset_query();
Attachments are all children of the post they are attached to, and you can use this to do your own custom gallery code. They also have a lot of data in their custom fields, such as image dimensions, EXIF data, etc They can even be commented on.
You can take the code from the inner loop and place it in attachment.php in your theme, just double check I haven't made any syntax typos before you do.
wp_get_attachment_metadatastores the file data. If a JPEG had EXIF data, that would've got stored there too. The posts table stores the attachment data (so things like the title, caption, author, date etc.). Nothing retarded about that in my books ;) – TheDeadMedic Jun 20 '11 at 18:16