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。

檢索帶有分隔符的類別父級。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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
檢視更多 >