Wordpress 获取父类别名称和内容

Wordpress 获取父类别名称和内容,wordpress,Wordpress,如何在类别页面中获取父类别信息。让我解释一下细节 说像我有类别一样 Photos Gallery one Gallery Two Gallery Three 我还使用了功能类别图像插件。。所以我的菜单是照片。所以当我点击照片时,它会显示所有的家长类别名称和特色图片 要素图像短代码为[FeatureDimagesat taxonomy='category'columns='3'] 我想我可以很容易地得到特征图像,但最主要的是如何用永久链接显示父类别名称 <?php g

如何在类别页面中获取父类别信息。让我解释一下细节

说像我有类别一样

Photos
  Gallery one
  Gallery Two
  Gallery Three
我还使用了功能类别图像插件。。所以我的菜单是照片。所以当我点击照片时,它会显示所有的家长类别名称和特色图片

要素图像短代码为[FeatureDimagesat taxonomy='category'columns='3']

我想我可以很容易地得到特征图像,但最主要的是如何用永久链接显示父类别名称

    <?php

get_header(); ?>


    <h1><?php if (is_category()) { single_cat_title(); } ?></h1>

   <?php
$category = get_the_category();
$parent = get_cat_name($category[0]->category_parent);
if (!empty($parent)) {
echo '&raquo; ' . $parent;
} else {
echo '&raquo; ' . $category[0]->cat_name;
}
?>



<?php get_footer(); ?>
使用以下命令:

//Get all terms in current category
$term =  $wp_query->queried_object;
现在您可以获取父类别ID

$parentId = $term->parent;
然后您可以获得描述:

echo category_description( $parentId );
完整代码:

//Get all terms in current category
$term =  $wp_query->queried_object;

//parent id
$parentId = $term->parent;

if($parentId == 0){
   echo category_description();
}else{
   echo category_description( $parentId );
}

你能复习一下你的问题吗?不清楚你想做什么!