我想在地图上显示产品类别的图片。 我想展示分类图片 我尝试了许多以下 WordPress 函数,当我得到 vardump 时,它给了我一个数组 这是我的地图的代码 在本节中,我想显示图像而不是图标
<?php
$args = array('post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1);
$wp_query = new WP_Query($args);
?>
<?php if ($wp_query->have_posts()) :
$posts = $wp_query->posts;
$GLOBALS['all_ads']=$posts;
$lenght = count($posts); ?>
<ul class="row items ad-listing">
<?php for ($i = 0; $i < $lenght; $i++) {
$single_post = $posts[$i];
$terms = wp_get_post_terms($single_post->ID, 'city_categories', array('order' => 'DESC'));
$parent_id = $terms[0]->parent;
$parent_id_1 = $terms[1]->parent;
$city_term = get_term_by('id', $parent_id, 'city_categories');
$name = $city_term->name;
$term_id = $terms[0]->term_id;
$term_id_two = $terms[1]->term_id;
$ad_type = get_post_meta($single_post->ID, 'ad_type','true');
$parent_id = $parent_id ? $parent_id :$parent_id_1;
if ($city_term_id == $term_id || $city_term_id == $term_id_two){
$data['lat'] = get_post_meta($single_post->ID, '_ad_latitude', true);
$data['long'] = get_post_meta($single_post->ID, '_ad_longitude', true);
$phone = get_post_meta($single_post->ID , 'shmarhtmascabt_v_shmarhtmascabt_m' , true);
$address = trim(get_post_meta($single_post->ID , 'adrs_v_shmarhtmascabt_m' , true));
$type = wp_get_post_terms($single_post->ID, 'product_cat')[0]->name;
$title = $single_post->post_title;
$ad_link = get_permalink($single_post->ID);
$sc_studi_cat_icon = get_term_meta($term_id->term_id, array( 1680,470 ), true);
print_r($sc_studi_cat_icon);
$img_cat=wp_get_attachment_image($sc_studi_cat_icon,array('71', '76'));
$src = wp_get_attachment_image_src( get_post_thumbnail_id($single_post->ID), '', false, '' );
$sc_studi_cat_icon = get_term_meta($type->term_id, 'sc_studi_cat_icon', true);
$img_cat=wp_get_attachment_image($sc_studi_cat_icon,array('71', '76') , false , 'src');
var_dump($img_cat);
$data['text']="<div class='map-div-container'><div><a href='{$ad_link}'><h4>{$title}</h4></a></div>";
if ($phone){$data['text'].="<div><i class='fas fa-phone' style='font-size: 10px;'></i><b>تلÙÙ†:</b> {$phone}</div>";}
if ($address){$data['text'].="<div><i class='fas fa-map-marker-alt'></i><b>آدرس:</b> {$address}</div>";}
if ($type){$data['text'].="<div><i class='far fa-folder'></i><b>نوع:</b> {$type}</div></div>";}
$data['text']=urldecode($data['text']);
$map_data[$single_post->ID] = $data;
}
if (($state_term_id === $parent_id || $state_term_id[0] === $parent_id) && ($ad_type == 1936)):
如果你能指导我如何做这将是一个很大的帮助。
提前致谢。
答案 0 :(得分:0)
$type3 = wp_get_post_terms($single_post->ID, 'product_cat')[0];
$category_thumbnail = get_woocommerce_term_meta($type3->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail);