Answer the question
In order to leave comments, you need to log in
Why doesn't it display one image from wordpress categories?
There is a widget that displays categories with pictures, all pictures except the first one are displayed, I statically transferred the id to wp_get_attachment_image_src, but it still doesn't return anything.
$title = apply_filters( 'widget_title', $instance['title'] );
$empty_category = apply_filters( 'widget_empty_category', $instance['empty_category'] );
$args = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'orderby' => 'none',
'parent' => 0
);
$terms = get_terms( $args );
$array_terms= array();
foreach ($terms as $i => $term) {
if ($term->slug == 'uncategorized'){
continue;
}
$term_id = $term->term_id;
$image_url = wp_get_attachment_image_src( $term_id, 'full' )[0];
r($term_id);
$array_terms[$i] = ['name' => $term->name,'src' => $image_url,'child' => array()];
$argschild = array(
'taxonomy' => 'product_cat',
'hide_empty' => $empty_category == "on" ? true : false,
'orderby' => 'none',
'parent' => $term_id
);
$termschild = get_terms( $argschild );
foreach ($termschild as $child) {
$term_link = get_term_link($child);
$array_terms[$i]['child'][] = ['name' => $child->name, 'link' => $term_link];
}
}
wp_reset_query();
?>
<h3 class="text-center"><?php echo $title; ?></h3>
<div class="widjets">
<?php foreach ($array_terms as $term): ?>
<div class="widjet">
<div class="title"><img src="<?php echo $term['src']; ?>"><span class="cat_name"><?php echo $term['name']; ?></span></div>
<ul class="list_subcat">
<?php foreach ($term['child'] as $term_child): ?>
<li><a href="<?php echo $term_child['link']; ?>"><?php echo $term_child['name']; ?></a></li>
<?php endforeach ?>
</ul>
</div>
<?php endforeach; ?>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question