How do you link an attachment image to its category?
function wp_attachment_image($size = thumb) {
if($images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1, // show all
'post_status' => null,
'post_mime_type' => 'image',
))) {
foreach($images as $image) {
$attimg = wp_get_attachment_image($image->ID,$size);
$atturl = wp_get_attachment_url($image->ID);
$attlink = get_attachment_link($image->ID);
$postlink = get_permalink($image->post_parent);
$atttitle = apply_filters('the_title',$image->post_title);
echo '<a href="'.$postlink.'">'.$attimg.'</a>';
}
}
}
wp_attachment_image('thumb');
I posted a short how to add extra fields to categories and once you have that done you can link the attachment using the attachment URL or the ID of the attachment.