I want to develop a category division like attached picture.
loop all product’s category name and category thumbnail (woocommerce), just like post loop.
`
<?php
$args = array(
// 'posts_per_page' => -1,
'taxonomy' => 'product_cat',
'orderby' => 'name',
// 'show_count' => 0,
// 'pad_counts' => 0,
// 'hierarchical' => 1,
// 'title_li' => '',
// 'hide_empty' => 0,
);
$loop = new WP_Query( $args );
while ( $loop->has_category( $category = '', $post = null ) ) : $loop->the_post();
global $product; ?>
<!-- !.p-item -->
<li class="p-item">
<a href="<?php get_category_link($loop->post->ID); ?>">
<?php if ( has_post_thumbnail( $loop->post->ID ) ) {
echo get_the_post_thumbnail($loop->post->ID, 'ihossain');
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/img/icon_category_image_1.svg" alt="<?php the_title(); ?>" />
<?php } ?>
<h6 class="icon-title"><?php $categoo = $product->get_categories(); echo $categoo; ?></h6>
</a>
</li>
<!-- !!.p-item -->
<?php endwhile; ?>
`
2
Answers
You can access all the categories and their thumbnail using this code.
Try this: