2017-07-28 71 views
0

我想在內容底部顯示Wordpress中存在的所有類別,其中當前帖子的選定內容爲粗體,如下所示。 例如,對於現有帖子,我選擇了3個現有的category2。顯示WP中的所有類別,並以粗體顯示

組別產品組別類別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

相關問題