dongyuduan1890 2017-01-04 05:33
浏览 35

WooCommerce产品列表视图:按列表视图中的共享子类别图像按子类别购买

Sorry, the title may be confused.

So far, all I find about the product list view for woocommerce are displaying all products under a category with their own images. But what I want is that the products are displayed within a category, for instance:

(in the example, "single Door single drawer bases" is the ultimate subcategory e.g Red cabinet->base cabinet(in red)->single door single drawer bases. in this case all the products in this category with different models are displayed in a list view with shared subcategory image.)

Is there any way (code, plugin or any other idea) to achieve this?

Thanks in advance!

enter image description here

  • 写回答

1条回答 默认 最新

  • douniang3866 2017-01-04 07:32
    关注

    To add the category image to the product list you can use this:

    add_action( 'woocommerce_before_shop_loop', 'woocommerce_category_image', 100 );
    function woocommerce_category_image() {
        if ( is_product_category() ){
            global $wp_query;
            $cat = $wp_query->get_queried_object();
            $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
            $image = wp_get_attachment_url( $thumbnail_id );
            if ( $image ) {
                echo '<img src="' . $image . '" alt="" />';
            }
        }
    }
    

    To adjust your product list to your needs you can either modify the template content-product.php directly (easy but dirty) or you use the actions hooks in there (recommended but a little bit tricky if you no familiar with this).

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)