カスタム WooCommerce テーマで製品カテゴリの画像を表示する php スニペットを見つけるための助けを探しています。ウィジェット内で php コードを実行するプラグインを使用していますが、製品カテゴリ名に対して正常に動作しています。カテゴリの画像に適したものが見つかりません。どんな助けでも大歓迎です。
2737 次
3 に答える
1
カテゴリIDを知っていて、次の場所にあると仮定します$cat_ID
。
// get the thumbnail ID
$thumbnail_id = get_woocommerce_term_meta( $cat_ID, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id );
// print the IMG HTML
echo '<img src="'.$image.'" />';
于 2012-11-01T00:41:20.243 に答える
0
現在 archive-product.php に表示されているカテゴリのカテゴリ画像を表示するには、is_product_category() が true のときに現在のカテゴリ term_id を使用します。
// verify that this is a product category page
if (is_product_category()){
global $wp_query;
// get the query object
$cat = $wp_query->get_queried_object();
// get the thumbnail id user the term_id
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id );
// print the IMG HTML
echo '<img src="'.$image.'" alt="" width="762" height="365" />';
}
于 2014-10-31T07:21:44.583 に答える
0
以下のコードを参照してください:-
global $product;
if (is_product_category()) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($thumbnail_id);
if ($image) {
echo '<img src="' . esc_url($image) . '" alt="" />';
} }
于 2016-06-28T10:46:42.960 に答える