get_category_parents

函数
get_category_parents ( $category_id, $link = false, $separator = '/', $nicename = false, $deprecated = array() )
参数
  • (int) $category_id Category ID.
    Required:
  • (bool) $link Optional. Whether to format with link. Default false.
    Required:
    Default: false
  • (string) $separator Optional. How to separate categories. Default '/'.
    Required:
    Default: '/'
  • (bool) $nicename Optional. Whether to use nice name for display. Default false.
    Required:
    Default: false
  • (array) $deprecated Not used.
    Required:
    Default: array()
返回值
  • (string|WP_Error) A list of category parents on success, WP_Error on failure.
定义位置
相关方法
get_category_by_pathget_category_childrenget_categoriesget_category_linkget_category
引入
1.2.0
弃用
-

get_category_parents: 这个函数在一个格式化的列表中检索给定类别的父类别。它需要三个参数:$category_id, $link, 和 $separator。

检索带有分隔符的类别父级。

function get_category_parents( $category_id, $link = false, $separator = '/', $nicename = false, $deprecated = array() ) {

	if ( ! empty( $deprecated ) ) {
		_deprecated_argument( __FUNCTION__, '4.8.0' );
	}

	$format = $nicename ? 'slug' : 'name';

	$args = array(
		'separator' => $separator,
		'link'      => $link,
		'format'    => $format,
	);

	return get_term_parents_list( $category_id, 'category', $args );
}

常见问题

FAQs
查看更多 >