Support

Account

Home Forums General Issues Display taxonomy term image field in page template

Solving

Display taxonomy term image field in page template

  • Hello,
    how can I display taxonomy term image field in page template?
    This is code I use and it’s not working:

    <section>
        <div class="container">
            <div class="row">
    
    			<?php
    			$queried_object = get_queried_object();
    			$taxonomy = $queried_object->taxonomy;
    			$term_id = $queried_object->term_id;  
    			
    			$terms = get_categories( array( 'taxonomy' => 'service', 'hide_empty' => false ) );
    			$term_image = get_field( 'tax_image', $taxonomy . '_' . $term_id );
    			
    			foreach ( $terms as $term ) : ?>
    			
    				<div class="col-lg-4 col-md-6">
    					<div class="product product-zoom product--card">
    						<div class="product__thumbnail">
    
    							<?php //if ( $term_image ) : ?>
    
    								<img src="<?php echo $term_image['url']; ?>" alt="<?php echo $term->name; ?>">
    
    							<?php //endif; ?>
    
    						</div>
    
    						<div class="product-desc">
    							<h4 class="text-center mb-2"><?php echo $term->name; ?></h4>
    						</div>
    					</div>
    				</div>				
    			
    			<?php
    			endforeach
    			?>
    			
            </div>
        </div>
    </section>

    Thanks for help.

  • old question popped to the top for spam.

    The code to show each term image:

    
    <?php 
    $terms = get_terms(array('taxonomy' => 'service', 'hide_empty' => false));
    foreach ($terms as $term) {
      $term_image = get_field( 'tax_image', $term);
      if ($term_image) {
        ?>
          <img src="<?php echo $term_image['url']; ?>" alt="<?php echo $term->name; ?>">
        <?php 
      }
    }
    ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.