Support

Account

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

Unread

Display taxonomy term image field in page template

    • Juraj_

    • May 3, 2021 at 7:23 pm

    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.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.