在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的
发布评论