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.

Having some trouble with taxonomy images plugin.

I am on single-post.php and I want to display my post's taxonomy terms & the term's associated images. Ideally, I'd like the taxonomy description there too. No idea why this has me stumped because it seems like it should be a simple thing to do.

I have this code, which displays just the post's term's images:

$terms = apply_filters( 'taxonomy-images-list-the-terms', '', array(
            'taxonomy' => 'comedians',
        ) );

        foreach( (array) $terms as $term){
            echo $term;
        }

I also have this, which displays the post's terms:

        print get_the_term_list( $post->ID, 'comedians', '<li>', ',</li><li>', '</li>' );

And then I have this code, which displays all of the term's images, with the terms & links & descriptions:

$terms = apply_filters( 'taxonomy-images-get-terms', '', array(
            'taxonomy' => 'comedians',
        ) );
        if ( ! empty( $terms ) ) {
            print "\n" . '<div class="row">';
            foreach( (array) $terms as $term ) {
                print "\n" . '<div class="four columns">';
                print "\n\t" . '<a href="' . wp_get_attachment_url( $term->image_id ) . '" rel="lightbox unique-woo-feature">' . wp_get_attachment_image( $term->image_id, 'unique-woo-feature' ) . '</a>';
                print "\n\t" . '<h5>' . esc_html( $term->name ) . '</h5>';
                print "\n\t" . '<p>' . esc_html( $term->description ) . '</p>';
                print "\n" . '</div>';
            }
            print "\n" . '</div>';
        }

What I need is something in between. I understand the crucial part is the filter, specifically the difference between get-terms and list-the-terms but the latter one, which gets the post's terms like I need, doesn't seem to do anything but just the images no matter what I do.

Any help with this, much appreciated.

share|improve this question

1 Answer 1

I was having trouble with this too. Wanted to show all the term images on a single post page. I found that you need to loop through the terms first (in my case, taxonomy=st_colors), then loop through the images associated with those terms. Here is how I solved it:

    <?php
$terms = get_the_terms( $post->ID, 'st_colors' );
foreach ($terms as $term) : 

    $colors = apply_filters( 'taxonomy-images-get-terms', '', array(
        'taxonomy' => 'st_colors',
            'term_args' => array(
                'slug' => $term->slug,
                )
        ) 
    );
    foreach( (array) $colors as $color) :
        echo wp_get_attachment_image( $color->image_id, 'full', array('class' => 'alignnone'));
        echo $term->name;
    endforeach;

endforeach;
?>

Hope that helps!

share|improve this answer

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.