I have a CPT with a custom taxonomy called 'equipment_cat'. I'm currently displaying the subcategories of a category on the category archive using the following code:
I'm using <a href="https://wordpress.org/plugins/taxonomy-images/" rel="nofollow noreferrer">Taxonomy Images</a> plugin to attach an image to each category. I've created a custom page template to display all top level categories with their images using this code:
I would like to display the sub categories of a category in the category archive but also include the image that are attached to the subcategory.
Code:
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
if ($term->parent == 0) {
wp_list_categories('taxonomy=equipment_cat&depth=1&show_count=0&title_li=&child_of=' . $term->term_id);
} else {
wp_list_categories('taxonomy=equipment_cat&show_count=0&title_li=&child_of=' . $term->parent);
}
?>
I'm using <a href="https://wordpress.org/plugins/taxonomy-images/" rel="nofollow noreferrer">Taxonomy Images</a> plugin to attach an image to each category. I've created a custom page template to display all top level categories with their images using this code:
Code:
<?php
$terms = apply_filters( 'taxonomy-images-get-terms', '', array(
'taxonomy'=>'equipment_cat',
'image_size' => 'medium',
'term_args' => 'parent=0',
'order' => 'ASC' ,
'orderby' => 'title',
'count' => 2) );
foreach( (array) $terms as $term){
echo '<div class="col-xs-6 col-sm-3 col-md-3">';
echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'medium' ) . '</a>' . '<h3>'. sprintf(__('%s', 'my_localization_domain'), $term->name) . '</h3>';
echo '<div class="description">';
echo $term->description;
echo '</div>';
echo '</div>';
}
?>
I would like to display the sub categories of a category in the category archive but also include the image that are attached to the subcategory.