Devbuddy
Devbuddy

Reputation: 231

Display the wordpress taxonomy image into front-end?

Trying to display the taxonomy images into front-end along with name and description and I need it in a loop, But I don't get how to use the code. Here I'm using a plugin Taxonomy Images [https://wordpress.org/plugins/taxonomy-images/] Please, can someone help me?

enter image description here

    <?php $terms = get_terms('category');
foreach($terms as $term):
$args = array(
'orderby' => 'title',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array($term->slug)
)
 ));
$tag_query = new WP_Query( $args );
if($tag_query->have_posts()):
$image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '' );
echo '<li>
    ' . wp_get_attachment_image( $term->image_id, 'detail' ) . '
    <a href="#">'.esc_html($term->name).'</a> 
    <p>'.esc_html($term->description).'</p>
    </li>';
while($tag_query->have_posts()):$tag_query->the_post();
endwhile;
endif;
wp_reset_postdata();
endforeach;
?>

Upvotes: 1

Views: 1356

Answers (1)

Pabari Mohit
Pabari Mohit

Reputation: 125

You can create a shortcode for yourself by adding a few lines to functions.php in your theme.

add_shortcode('taximage', 'taximage');
function taximage() {
      global $post;
      return apply_filters( 'taxonomy-images-list-the-terms', '', array('post_id' => $post->ID, 'taxonomy' => 'colors') );
}

Now you can add the [taximage] shortcode to your Views / Content Templates.

Upvotes: 1

Related Questions