I have loop that displays all terms from custom taxonomy. I also have image field, attached to custom taxonomy. Now, I want to display image in my page template:
<?php
/* Template Name: Služby */
get_header();
?>
<section id="sluzby" class="section--padding" style="background: #eff1f5;">
<div class="container">
<div class="row">
<?php
$terms = get_terms( array( 'taxonomy' => 'sluzba', 'hide_empty' => false ) );
$term_image = get_field( 'tax_image' );
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="Služba <?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>
<?php
get_footer();
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I did it by this example:
https://support.advancedcustomfields.com/forums/topic/loop-to-display-acf-image-of-taxonomy-term/
<?php
$terms = get_terms( array( 'taxonomy' => 'sluzba', 'hide_empty' => false ) );
foreach ( $terms as $term ) :
$term_image = get_field( 'tax_image', 'sluzba_' . $term->term_id ); ?>
<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="Služba <?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
?>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
