WordPress获取分类法所有子级函数:get_term_children

本站正在使用的主机

本站目前托管于腾讯云香港轻量服务器,价格便宜访问速度也快,使用本站推荐链接购买还可免费获得WordPress运行环境优化服务。

最新活动 »

WordPress函数get_term_children用于获取指定分类法的所有子级,例如:获取某个分类的所有子分类,该函数返回所有分类法子级的ID。

get_term_children( int $term_id, string $taxonomy )

函数参数

$term_id

整数

如果分类法为category,则传递分类的ID

$taxonomy

字符串

分类法的名称

函数返回值

以数组的形式返回所有子级的ID

函数使用示例

$childrens = get_term_children(6, 'category');
foreach($childrens as $cat) {
	echo '<li><a href="' . get_category_link($cat) . '">' . get_cat_name($cat) . '</a></li>';
}

扩展阅读

get_term_children()函数位于:wp-includes/taxonomy.php

相关函数:

背字根微信二维码

本站文章均为原创,码字非常不容易,转载请注明原文出处,给苦逼的作者保留一点创作动力。