Php 使用分类图像显示顶级Woocommerce产品标签

Php 使用分类图像显示顶级Woocommerce产品标签,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,查看显示添加到产品标签分类中的图像缩略图 通过修改以下内容以使用标记,我成功地将图像上载字段添加到后端的product_标记分类中: 你就快到了。你只需要做两件事: 获取图像id 输出图像。 这里有一个更新版本的循环,可以完成这两件事。您可以更改wp_get_attachment_image的第二个参数来更改图像大小 $taxonomy = 'product_tag'; //Choose the taxonomy $terms = get_terms( $taxonomy ); //Get

查看显示添加到产品标签分类中的图像缩略图

通过修改以下内容以使用标记,我成功地将图像上载字段添加到后端的product_标记分类中:


你就快到了。你只需要做两件事:

获取图像id 输出图像。 这里有一个更新版本的循环,可以完成这两件事。您可以更改wp_get_attachment_image的第二个参数来更改图像大小

$taxonomy = 'product_tag'; //Choose the taxonomy
$terms = get_terms( $taxonomy ); //Get all the terms

foreach ($terms as $term) { //Cycle through terms, one at a time

// Check and see if the term is a top-level parent. If so, display it.
$parent = $term->parent;
if ( $parent=='0' ) {

$term_id = $term->term_id; //Define the term ID
$term_link = get_term_link( $term, $taxonomy ); //Get the link to the archive page for that term
$term_name = $term->name;
$slug = $term->slug;
$factwpslug = "/shop/?fwp_category=";
$distance = "&fwp_sort=distance";

// Get the image ID here using the $term_id from above and the meta key you used to save the ID
$image_id = get_term_meta ( $term_id, 'product_tag-image-id', true );


// Use wp_get_attachment_image() to get the image HTML
echo '<li><a class="'. $slug . ' top-level-cat-nav" href="' . $factwpslug . $slug . $distance . '"><span class="label">' . $term_name . '</span>' . wp_get_attachment_image ( $image_id, 'large' ) . '</a></li>';

}
}

就这样,我们成功了。几个小时前就该问了,但继续尝试不同的选择总是好的。非常感谢。这可能对其他人也有用。