Last active
June 1, 2020 22:28
-
-
Save amouratoglou/851ad3eb3c8bc0796a94e9ae311d6119 to your computer and use it in GitHub Desktop.
Woocommerce Taxonomy Term list with featued image for loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// this function can be used anyplace on your template and will show full size featured images of taxonomy terms, | |
// replace $term_id with the right ID and enjoy your life. | |
$term_id = 37; | |
$taxonomy = 'product_cat'; | |
// Get subcategories of the current category | |
$terms = get_terms([ | |
'taxonomy' => $taxonomy, | |
'hide_empty' => false, | |
'parent' => $term_id | |
]); | |
$output = '<div class="subcategories-list">'; | |
// Loop through product subcategories WP_Term Objects | |
foreach ( $terms as $term ) { | |
$thumbnail_id = get_term_meta($term->term_id, 'thumbnail_id', true); | |
$image = wp_get_attachment_image_src( $thumbnail_id, 'full' ); | |
$term_link = get_term_link( $term, $taxonomy ); | |
// render stuff and make the world a better place | |
$output .= '<div class="term-item"> | |
<img src="'. $image[0] .'"> | |
<a href="'. $term_link .'">'. $term->name .'</a></li>'; | |
} | |
echo $output . '</div>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment