2017-07-28 12 views
0

Wordpressにあるすべてのカテゴリをコンテンツの下部に表示したい場合は、現在のポスト用に選択したものを次のように表示します。 たとえば、既存の投稿の場合、私は既存のカテゴリ2の3を選択しました。WPですべてのカテゴリを太字で表示する

カテゴリ1カテゴリ2 カテゴリー3

私はこれをどのように行うことができますか?

私のコード(今だけ選択したカテゴリを表示):すべてのカテゴリ

<div class="entry-meta"> 
<span class="term-links"> 
<?php foreach (get_the_terms($post->ID, 'category') as $term) : 
?> 
<a href="<?php echo esc_url(get_term_link($term->term_id)) 
?>"><span class="<?php echo $term->slug ?>"><?php echo $term->name ?> 
</span></a> 
<?php endforeach; ?> 
</span> 

<style> 
.term-links .category2 { 
display: inline-block; 
font-weight:bold; 
</style> 
+0

を追加し、あなたのコードを共有してください。私たちは答えを与えることができます。 –

+0

@ShitalMarakanaあなたはそれを持っています – Santiago

答えて

0

リストは、テンプレート内のコードの下に

<style type="text/css"> 
     .single-product div.product .product_meta .product_cat ul li{ list-style-type:circle;} 
     .single-product div.product .product_meta .product_cat ul li.current-cat{list-style-type:circle;} 
     .single-product div.product .product_meta .product_cat ul li.current-cat a{display: inline-block;font-weight:bold;} 
     </style> 
     <?php 
     global $post; 
     $terms = get_the_terms($post->ID, 'product_cat'); 
     $product_cat_id_array = array(); 
     foreach ($terms as $term ) { 
      $product_cat_id_array[] = $term->term_id; 
     } 
     $product_cat_id_string = implode(",",$product_cat_id_array); 

     $args = array(
      'child_of'   => 0, 
      'current_category' => $product_cat_id_string, 
      'depth'    => 0, 
      'echo'    => 1, 
      'exclude'    => '', 
      'exclude_tree'  => '', 
      'feed'    => '', 
      'feed_image'   => '', 
      'feed_type'   => '', 
      'hide_empty'   => 0, 
      'hide_title_if_empty' => false, 
      'hierarchical'  => true, 
      'order'    => 'ASC', 
      'orderby'    => 'name', 
      'separator'   => '', 
      'show_count'   => 0, 
      'show_option_all'  => '', 
      'show_option_none' => __('No categories'), 
      'style'    => 'list', 
      'taxonomy'   => 'product_cat', 
      'title_li'   => __('Categories'), 
      'use_desc_for_title' => 0, 
     ); 
     wp_list_categories($args); 
    ?> 
+0

それは現在のカテゴリを表示します、@ ShitalMarakana – Santiago

+0

あなたはシングルポストでコードを使用していますか?詳細ページ右。 –

+0

私は正確に何をしましたか:WooCommerce製品のカスタムタクソノミを作成します(この例では 'category')。簡単な説明の後で、現在利用可能なすべての「カテゴリ」を太字でプロダクトに割り当てて表示します。提供されたコードで私はそれが製品に割り当てられていることを示していますが、私はそれらのすべてを表示する必要があります。 @shitalmarakana – Santiago

関連する問題