简体   繁体   English

始终获得父类别名称Wordpress

[英]Always get parent category name Wordpress

I just would like to get and display the parent (or grand parent if necessary) category name in WordPress. 我只是想获取并显示WordPress中的父类别(或父类别,如果需要)。

I have this : 我有这个 :

single_cat_title()

But it display the actual category name. 但它显示实际的类别名称。

My code is in header.php 我的代码在header.php中

In this image, in the green part it must be written "Energies Renouvelables" 在此图中,绿色部分必须写为“ Energies Renouvelables” 在此处输入图片说明

Have an idea ? 有想法吗?

EDIT 编辑

This is my code, nothing special like I said .. 这是我的代码,没什么特别的。

<div class="fil-arianne">
    <?php echo single_cat_title(); //echo get_the_title($parentID);?>
</div>

To do this you can use get_category_parents() . 为此,您可以使用get_category_parents() So you would call it like this: 因此,您可以这样称呼它:

get_category_parents( $cat, true, ' &raquo; ' );

Which would display something like: 它将显示如下内容:

The Parent Category » My Category » 

For the full list of arguments, take a look at the codex . 有关参数的完整列表,请看一下Codex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM