Link Attachment Image to Category

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');

Related posts

Leave a Reply

1 comment