Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.