我正在尝试展示woocommerce类别图片。如果产品没有图像我尝试使用此代码,但它不起作用。我不知道我做错了什么。使用此代码显示src“(未知)”。
if ( has_post_thumbnail() ) {
// thets work ok .....
}else{
global $wp_query;
// get the query object
$cats = $wp_query->get_queried_object();
// get the thumbnail id using the queried category term_id
$thumbnail_ids = get_woocommerce_term_meta( $cats->term_id, 'thumbnail_id', true );
// get the image URL
$images = wp_get_attachment_url( $thumbnail_ids );
$output .= '<a href="'.$urllink.'" title="' . esc_attr( get_the_title() ) . '">';
$output .= '<img src="' . $images . '" alt="Placeholder" width="300" class="woocommerce-placeholder wp-post-image" height="300">';
$output .= '</a>';
}
答案 0 :(得分:0)
试试这个:
<?php
if ( has_post_thumbnail( $loop->post->ID ) ) {
echo get_the_post_thumbnail( $loop->post->ID, 'shop_catalog' );
} else {
echo '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" />';
}
?>