I'm using Taxonomy Images, and I can't figure out how to display a category's associated image on a single.php. Essentailly, when a user is viewing a post that utilizes the single.php template, it should display the post's category's image. Right now, it just doesn't display anything.

This is the code that I'm using:

    $image_id = apply_filters( "taxonomy-images-queried-term-image-id", 0 );
    if ( ! empty( $image_id )):
    print apply_filters( "taxonomy-images-queried-term-image", "",  array(
        "image_size" => "large"
    ) );
  • Which part of this doesn't work? Do you get the proper image_id? – montrealist Jul 23 '13 at 19:13
  • I'm not sure, no code shows up in the areas where the images should appear. – JacobTheDev Jul 24 '13 at 13:04
up vote 5 down vote accepted

I used this little trick to obtain the taxonomy image given the ID of the term:

    $images = get_option('taxonomy_image_plugin');
    $img_url = wp_get_attachment_url( $images[$term_id] ); 
  • Thanks. I wonder how to use the filter proposed by the own plugin author $image_id = apply_filters( 'taxonomy-images-queried-term-image-id', 0 ); – Pablo S G Pacheco Dec 7 '15 at 16:41

Building on @Lorenzo's answer, you still need to get term_id. This works, but seems less than ideal:

$images = get_option( 'taxonomy_image_plugin' );
$terms = get_the_terms( $post->ID, 'byline' );
foreach ( $terms as $term ) {
    $img_url = wp_get_attachment_url( $images[$term->term_id] ); 
    print $img_url;

The discussion here may be helpful.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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