功能:
cat_is_ancestor_of()函数用来判断一个分类是否是另一分类的父节点。
用法:
参数:
$cat1
(int/object) (必须的) 父分类的ID或者对象
默认: 无默认值
$cat2
(int/object) (必须的) 子分类的ID或者对象
默认: 无默认值
返回值:
(bool) 如果$cat1是$cat2的父分类,就返回真,否则返回假。
所在位置:
cat_is_ancestor_of() 包含在 wp-includes/category.php
源码:
/**
* Check if a category is an ancestor of another category.
*
* You can use either an id or the category object for both parameters. If you
* use an integer the category will be retrieved.
*
* @since 2.1.0
*
* @param int|object $cat1 ID or object to check if this is the parent category.
* @param int|object $cat2 The child category.
* @return bool Whether $cat2 is child of $cat1
*/
function cat_is_ancestor_of( $cat1, $cat2 ) {
return term_is_ancestor_of( $cat1, $cat2, 'category' );
}
示例:
相关函数:
term_is_ancestor_of()
感觉本站内容不错,读后有收获?小额赞助
还可以分享文章给好友: