获取 Woocommerce 类别缩略图 [英] Get Woocommerce Category Thumbnails

查看:44
本文介绍了获取 Woocommerce 类别缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于 woocommerce 类别页面的自定义模板,仅用于显示类别.我让系统获取子类别的列表(通过使用 get_term_children($id, 'product_cat')get_term_by(...)),但它只返回包含所有必需信息的对象,缩略图数据除外.有谁知道我如何获得该术语的缩略图?

I have a custom template for a woocommerce category page to only display the categories. I have got the system to get a list of the child categories (by using get_term_children($id, 'product_cat') and get_term_by(...)), but it only returns objects containing all the required information, except the thumbnail data. Does anyone know how I can get the thumbnail for the term?

推荐答案

整理了一下,这里是我用的代码:

Sorted it, here's the code I used:

$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );

这篇关于获取 Woocommerce 类别缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆