Grabbing corresponding image for "get_terms" list?
-
I’m using the following code to get a list of terms from a custom taxonomy called “characters” :
<?php $terms = get_terms("character"); $count = count($terms); if ( $count > 0 ){ echo "<ul>"; foreach ( $terms as $term ) { echo '<li><a href="' . get_term_link($term) . '">'. $term->name . '</a></li>'; } echo "</ul>"; } ?>
Right now it outputs a clickable, alphabetical list of all the terms in that taxonomy. What I’d like it to also do is display a clickable thumbnail image that represents that term above the link.
So for example, if some of my terms include R2D2, Chewbacca, Han Solo, and Yoda, I’d like it to grab a thumbnail of the respective characters that I have placed in an image folder somewhere on my server. From what I have gleaned, this could be achieved by getting a chunk of code to pull up something like “/images/characters/”get_term”.jpg” and giving the thumbnail the same name as the term slug. However, I’m inexperienced with PHP, so I don’t know how to achieve that, nor how to implement it in the above code.
Any advice would be appreciated. Thank you for your time.
- The topic ‘Grabbing corresponding image for "get_terms" list?’ is closed to new replies.