Show term image in a query loop
-
Hello
I try to display the term image in a function.
Any help would be really appreciated.add_shortcode( 'cat_suppliers', 'display_cat_suppliers' ); function display_cat_suppliers($term_id) { ?> <div class="supplier_categories"> <?php ob_start(); // your taxonomy name $tax = 'supplier_category'; // get the terms of taxonomy $terms = get_terms( $tax, [ 'parent' => 0, 'number' => 8, 'hide_empty' => true, // do not hide empty terms ]); // Randomize Term Array shuffle( $terms ); // loop through all terms foreach( $terms as $term ) { $image = apply_filters( 'taxonomy-images-queried-term-image', '', array( 'image_size' => 'portfolio_4_col' ) ); // if no entries attached to the term //if( 0 == $term->count ) // display only the term name // echo '<h4>' . $term->name . '</h4>'; // if term has more than 0 entries // display link to the term archive ?> <div class="supplier_4_col_item_wrapper mix"> <a href="<?php echo get_term_link( $term ); ?>"> <div class="supplier-item"> <figure> <div class="supplier-item-thumbnail"> <?php print $image;?> </div> <figcaption class="supplier-item-hover"> <div class="cat-supplier-item-title"> <span> <?php echo $term->name; ?></span> </div> </figcaption> </figure> </div> </a> </div> <?php } return ob_get_clean(); ?> </div> <?php }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Show term image in a query loop’ is closed to new replies.