2016-08-08 24 views
0

私はワードプレスでは新しく、RT-テーマ17を使用しています。私は電子商取引サイトを開発しています。製品の詳細。そこに商品カテゴリの名前を表示する方法。ワードプレスの製品詳細ページで製品のカテゴリ名を取得する方法

また、私は、このソースコードを使用するが、私はカテゴリID(term_id)

$cate = get_queried_object();  
$cateID = $cate->term_id;  
echo $cateID; 

を取得できませんでした私は結果が見つかりました -

WP_Post Object 
(
    [ID] => 1140 
    [post_author] => 1 
    [post_date] => 2016-07-27 13:42:38 
    [post_date_gmt] => 2016-07-27 13:42:38 
    [post_content] => Energizer professional series heavy duty jumper cables for all vehicle types plus full size trucks, vans and SUVs. Red/black PVC-coated insulated clamps for easy identification. Tangle-free cables remains flexible even at -40°C. Heavy duty copper. 1 Gauge, 30 Ft, 800 AMP. All weather use. 
    [post_title] => ENB130 
    [post_excerpt] => 
    [post_status] => publish 
    [comment_status] => closed 
    [ping_status] => closed 
    [post_password] => 
    [post_name] => enb130 
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2016-08-03 19:05:34 
    [post_modified_gmt] => 2016-08-03 19:05:34 
    [post_content_filtered] => 
    [post_parent] => 0 
    [guid] => http://energizerpower.com/?post_type=products&p=1140 
    [menu_order] => 0 
    [post_type] => products 
    [post_mime_type] => 
    [comment_count] => 0 
    [filter] => raw 
) 

答えて

0

あなたは、コードの下に試すことができます。その製品に割り当てられているすべてのカテゴリ(コンマで区切られた)を表示します。

<?php global $post, $product; 

$cat_count = sizeof(get_the_terms($post->ID, 'product_cat')); ?> 
<?php echo $product->get_categories(', ', '<span class="posted_in">' . _n('Category:', 'Categories:', $cat_count, 'woocommerce') . ' ', '</span>'); ?> 
関連する問題