如何通过我的主题在主题搜索页面中加载woocommerce类别ID(例如Mustang Lite是我的主题)$ cat_id = 1242;我的代码。如何在som产品中检测类别ID
global $woocommerce;
global $wp_query;
$cat_id=1242;
$table_name = $wpdb->prefix . "woocommerce_termmeta";
$query="SELECT meta_value FROM {$table_name} WHERE `meta_key`='thumbnail_id' and woocommerce_term_id ={$cat_id} LIMIT 0 , 30";
$result = $wpdb->get_results($query);
foreach($result as $result1){
$img_id= $result1->meta_value;
}
echo '<img src="'.wp_get_attachment_url( $img_id ).'" alt="category image">';
答案 0 :(得分:0)
我在主题搜索中得到它的工作加载类别图像,例如Mustang Lite确认它是否适用于所有其他用户
if ( has_post_thumbnail() ) {
$thumb_size = ( ! function_exists( 'wma_amplifier' ) ) ? ( array( 100, 100 ) ) : ( 'admin-thumbnail' );
$output .= '<a href="'.$urllink.'" title="' . esc_attr( get_the_title() ) . '">';
$output .= get_the_post_thumbnail( get_the_ID(), $thumb_size );
$output .= '</a>';
}else{
$terms = get_the_terms( $prod_id, 'product_cat' );
if($terms) {
foreach ($terms as $key => $term) {
$cats_ids_array[$key] = $term->term_id;
}
global $woocommerce;
global $wp_query;
$cat_id=implode( ",", $cats_ids_array );
$table_name = $wpdb->prefix . "woocommerce_termmeta";
$query="SELECT meta_value FROM {$table_name} WHERE `meta_key`='thumbnail_id' and woocommerce_term_id ={$cat_id} LIMIT 0 , 30";
$result = $wpdb->get_results($query);
foreach($result as $result1){
$img_id= $result1->meta_value;
}
$output .= '<a href="'.$urllink.'" title="' . esc_attr( get_the_title() ) . '">';
$output .= '<img src="'.wp_get_attachment_url( $img_id ).'" alt="Placeholder" width="300" class="woocommerce-placeholder wp-post-image" height="300">';
$output .= '</a>';
}
}