get_category_children

函式
get_category_children ( $id, $before = '/', $after = '', $visited = array() )
引數
  • (int) $id Category ID to retrieve children.
    Required:
  • (string) $before Optional. Prepend before category term ID. Default '/'.
    Required:
    Default: '/'
  • (string) $after Optional. Append after category term ID. Default empty string.
    Required:
    Default: (empty)
  • (array) $visited Optional. Category Term IDs that have already been added. Default empty array.
    Required:
    Default: array()
返回值
  • (string)
相關
  • get_term_children()
定義位置
相關方法
get_term_children_get_term_childrenget_category_linkget_page_childrenget_category_parents
引入
1.2.0
棄用
2.8.0

get_category_children: 這個函式檢索一個給定類別的子類別的類別ID陣列。它需要兩個引數:$category_id和$args。

檢索術語ID前後分開的類別子女列表。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {
_deprecated_function( __FUNCTION__, '2.8.0', 'get_term_children()' );
if ( 0 == $id )
return '';
$chain = '';
/** TODO: Consult hierarchy */
$cat_ids = get_all_category_ids();
foreach ( (array) $cat_ids as $cat_id ) {
if ( $cat_id == $id )
continue;
$category = get_category( $cat_id );
if ( is_wp_error( $category ) )
return $category;
if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {
$visited[] = $category->term_id;
$chain .= $before.$category->term_id.$after;
$chain .= get_category_children( $category->term_id, $before, $after );
}
}
return $chain;
}
function get_category_children( $id, $before = '/', $after = '', $visited = array() ) { _deprecated_function( __FUNCTION__, '2.8.0', 'get_term_children()' ); if ( 0 == $id ) return ''; $chain = ''; /** TODO: Consult hierarchy */ $cat_ids = get_all_category_ids(); foreach ( (array) $cat_ids as $cat_id ) { if ( $cat_id == $id ) continue; $category = get_category( $cat_id ); if ( is_wp_error( $category ) ) return $category; if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) { $visited[] = $category->term_id; $chain .= $before.$category->term_id.$after; $chain .= get_category_children( $category->term_id, $before, $after ); } } return $chain; }
function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {
	_deprecated_function( __FUNCTION__, '2.8.0', 'get_term_children()' );
	if ( 0 == $id )
		return '';

	$chain = '';
	/** TODO: Consult hierarchy */
	$cat_ids = get_all_category_ids();
	foreach ( (array) $cat_ids as $cat_id ) {
		if ( $cat_id == $id )
			continue;

		$category = get_category( $cat_id );
		if ( is_wp_error( $category ) )
			return $category;
		if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {
			$visited[] = $category->term_id;
			$chain .= $before.$category->term_id.$after;
			$chain .= get_category_children( $category->term_id, $before, $after );
		}
	}
	return $chain;
}

常見問題

FAQs
檢視更多 >