wordpress - Display all categories in WP, with the selected in bold -


i want display categories existing in wordpress in bottom of content, selected current post in bold, follows. example, existing post selected category2 of 3 existing.

category1 category2 category3

how can this?

my code (now display selected category):

<div class="entry-meta"> <span class="term-links"> <?php foreach ( get_the_terms( $post->id, 'category') $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> 

list of category

add below code in template

<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  $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);      ?> 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -