如何在单个自定义 post 类型页面上将带有 link 的分类列表显示到分类页面

How to display taxonomy list with link to taxonomy page on the single custom post type page

我需要列出适用于此 post 的分类法。如果分类法只有一个,那么此代码运行良好:

global $post;
  $terms = wp_get_post_terms($post->ID, 'gintype');
  if($terms){
  $output = array();
  foreach($terms as $term){
   $outputnk[] = get_term_link( $term->slug, 'gintype');
   $outputme[] = $term->name;
   }
}

但是如果 post 有多个分类项,则此代码不起作用。

这段代码对我有用:

global $post;
   $terms = wp_get_post_terms($post->ID, 'gintype');
   foreach($terms as $term){
     $term_link = get_term_link( $term );
     echo '<div><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>';
   }