【问题标题】:How to add a category image menu to my shop page?如何将类别图像菜单添加到我的商店页面?
【发布时间】:2018-09-28 14:35:22
【问题描述】:

我想添加一个仅包含产品类别图像的附加菜单。我正在使用woocommerce。我希望它位于页面中间并下拉。这需要什么样的短代码?我试过使用 Mega Menu 插件,但它只会改变我的主菜单。

谢谢!

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    我认为没有直接的方法,您可以使用此代码获取类别图像 URL 的数组,然后您可以使用“woocommerce_before_shop_loop”操作,循环遍历数组并将图像放入您喜欢的 HTML 表单。

    add_action( 'woocommerce_before_shop_loop', function() {
        $categories = get_terms( 'product_cat' );
        $categories_thumbnails_urls = [];
        foreach ( $categories as $category ) {
            $thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
            $thumbnail_url = wp_get_attachment_url( $thumbnail_id );
            if ( empty( $thumbnail_url ) ) {
                continue;
            }
            $categories_thumbnails_urls[] = $thumbnail_url;
        }
    
        foreach ( $categories_thumbnails_urls as $cat_thumb_url ) {
            // ...
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-23
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 2013-07-24
      相关资源
      最近更新 更多