Php 定制商业主题中的产品类别图像
我正在寻找一个php代码片段,该代码片段将在自定义主题中显示产品类别图像。我正在使用一个插件,它在一个小部件中执行php代码,对于产品类别名称来说,它工作得很好。我就是找不到任何适合分类图像的东西。任何帮助都将不胜感激。假设您知道类别ID,并且它位于Php 定制商业主题中的产品类别图像,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在寻找一个php代码片段,该代码片段将在自定义主题中显示产品类别图像。我正在使用一个插件,它在一个小部件中执行php代码,对于产品类别名称来说,它工作得很好。我就是找不到任何适合分类图像的东西。任何帮助都将不胜感激。假设您知道类别ID,并且它位于$cat\u ID: // get the thumbnail ID $thumbnail_id = get_woocommerce_term_meta( $cat_ID, 'thumbnail_id', true ); // get the im
$cat\u ID
:
// get the thumbnail ID
$thumbnail_id = get_woocommerce_term_meta( $cat_ID, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id );
// print the IMG HTML
echo '<img src="'.$image.'" />';
//获取缩略图ID
$thumbnail\u id=获取商业术语元($cat\u id,'thumbnail\u id',true);
//获取图像URL
$image=wp\u get\u attachment\u url($thumbnail\u id);
//打印IMG HTML
回声';
要在archive-product.php中显示当前显示类别的类别图像,请在is\u product\u category()为true时使用当前类别术语\u id:
// verify that this is a product category page
if (is_product_category()){
global $wp_query;
// get the query object
$cat = $wp_query->get_queried_object();
// get the thumbnail id user the term_id
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id );
// print the IMG HTML
echo '<img src="'.$image.'" alt="" width="762" height="365" />';
}
//验证这是一个产品类别页面
如果(是产品类别()){
全局$wp_查询;
//获取查询对象
$cat=$wp\u query->get\u queryed\u object();
//获取缩略图id用户的术语\u id
$thumbnail\u id=获取商业术语元($cat->term\u id,'thumbnail\u id',true);
//获取图像URL
$image=wp\u get\u attachment\u url($thumbnail\u id);
//打印IMG HTML
回声';
}
参考以下代码:-
global $product;
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="' . esc_url($image) . '" alt="" />';
} }
global$产品;
如果(是产品类别()){
全局$wp_查询;
$cat=$wp\u query->get\u queryed\u object();
$thumbnail\u id=获取商业术语元($cat->term\u id,'thumbnail\u id',true);
$image=wp\u get\u attachment\u url($thumbnail\u id);
如果($image){
回声';
} }
谢谢您的回复。我对这个很陌生。你知道有什么方法可以检测到这个类别吗?我希望所有类别页面都有一个侧边栏。使用
正确填充标题即可,然后您可以使用$term->term\u id
获取类别id: