WordPress的

编程入门 行业动态 更新时间:2024-10-18 14:25:23
本文介绍了WordPress的-获取当前类别的父母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在category.php中,我如何针对具有父类别的类别进行测试?

In category.php, how would I test against a category having a parent category?

如果父类别为A,子类别为B,并且用户加载了类别B的URL,我希望能够测试它是否具有父A,并运行它(如果有)。

If the parent category is A, and the sub-category is B, and the user loads the URL for category B, I would like to be able to test if it has parent A, and run code if it does.

get_category_parents标记,但它似乎返回链接列表而不是数组:

I've found the get_category_parents tag, but it seems to return a link list rather than an array:

get_category_parents($cat, TRUE, ', '));

即使我得到了数组,我也不知道针对它进行测试的php函数是什么(php noob)。

Even if I got the array, I'm not sure what the php function is to test against it (php noob).

谢谢!

推荐答案

您可以使用 cat_is_ancestor_of 函数来检查类别是另一类的孩子。例如,检查当前类别是否是名为博客的类别的子代:

You can use the cat_is_ancestor_of function to check if a category is a child of another category. For example to check if the current category is a child of a category named 'blog':

cat_is_ancestor_of(get_cat_id('blog'), get_query_var('cat'))

更多推荐

WordPress的

本文发布于:2023-11-22 05:57:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616228.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WordPress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!