最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Woocommerce List categories with Image thumbnail

programmeradmin0浏览0评论

I installed WooCommerce 4 and I am trying to list out all the categories with thumbnails. Can I achieve it by a plugin or widget? Or I have to write the codes by myself?

The thing I want to achieve is similar to this:

Thanks in advance!

I installed WooCommerce 4 and I am trying to list out all the categories with thumbnails. Can I achieve it by a plugin or widget? Or I have to write the codes by myself?

The thing I want to achieve is similar to this:

Thanks in advance!

Share Improve this question asked May 18, 2020 at 10:09 RaptorRaptor 2721 gold badge3 silver badges24 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Try this code:

    $taxonomyName = "product_cat";

    $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false));

    echo '<ul>';
    foreach ($parent_terms as $pterm) {


        echo '<li><a href="' . get_term_link($pterm->name, $taxonomyName) . '">' . $pterm->name . '</a></li>';

        $thumbnail_id = get_woocommerce_term_meta($pterm->term_id, 'thumbnail_id', true);

        $image = wp_get_attachment_url($thumbnail_id);

        echo "<img src='{$image}' alt='' width='400' height='400' />";

        //Get the Child terms
        $terms = get_terms($taxonomyName, array('parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => false));
        foreach ($terms as $term) {

            echo '<li><a href="' . get_term_link($term->name, $taxonomyName) . '">' . $term->name . '</a></li>';
            $thumbnail_id = get_woocommerce_term_meta($pterm->term_id, 'thumbnail_id', true);

            $image = wp_get_attachment_url($thumbnail_id);

            echo "<img src='{$image}' alt='' width='400' height='400' />";
        }
    }
    echo '</ul>';
发布评论

评论列表(0)

  1. 暂无评论