WordPress显示当前文章分类和父分类的链接我相信需要代码的人也挺多,WordPress显示当前文章分类和父分类的链接代码如下自己把代码放到您要显示的地方吧。


$categories = get_the_category();
echo '<ul>';
echo '<li> Parent Category: ';
foreach( $categories as $category ){
     if($category->parent != 0){
          $parent_category = get_term( $category->parent );
          echo '<a href="' . esc_url( get_category_link($parent_category->term_id)) . '">' . esc_html($parent_category->name) . ' </a>';
          break;
     }
}
echo '</li>';
echo '<li>Subcategory: ';
foreach( $categories as $category ){
     if($category->parent != 0){
          echo '<a href="' . esc_url( get_category_link($category->term_id)) . '">' . esc_html($category->name) . ' </a>';
     }
}
echo '</li></ul>';