2016-04-12 10 views
1

私はwoocomerceのmysqlデータベースから私のカテゴリの画像を返したいと思います。私は何をすべきか、データベースからどのようにイメージを返すことができるか分かりません。woocomerce - mysqlからカテゴリ画像を取得

私を助けてください。

これまでのところ、私はちょうどどのように私はそうすることができる

SELECT * from `wp_terms` where term_id in (SELECT term_id FROM `wp_term_taxonomy` WHERE `taxonomy` LIKE 'product_cat' AND `parent` = 0 and count>0) 

、カテゴリ名とIDEを返しますか?

答えて

3
Try below code: 

    $catTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC')); 
    foreach($catTerms as $catTerm) : 
    $thumbnail_id = get_woocommerce_term_meta($catTerm->term_id, 'thumbnail_id', true); 
    // get the image URL 
    $image = wp_get_attachment_url($thumbnail_id); 
    <li> 
     <img src="<?php echo $image; ?>" width="152" height="245"/> 
     <span><?php echo $catTerm->name; ?></span> 
    </li> 
    endforeach; 
+0

おかげで、質問を、私は空のPHPページを持って、私は、これらのクラスにアクセスするには、私のページに何を含める必要がありますし、機能 ? –

+0

空のページからカスタムテンプレートページを作成してこのコードを使用することができます。 –

+0

お返事ありがとうございます、私に例を挙げてください。どうすればいいですか? –

0

現在表示されているカテゴリのカテゴリ画像を表示する - 返信用

// 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 using the queried category 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' />"; 
} 
関連する問題