wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes
get_term_parents_list › WordPress Function
Depuis4.8.0
Dépréciéen/a
› get_term_parents_list ( $term_id, $taxonomy, $args = array() )
| Paramètres: (3) |
|
| Retourne: |
|
| Défini(e) dans: |
|
| Codex: |
Retrieves term parents with separator.
Fonctions en relation: get_theme_feature_list, get_category_parents, get_term_to_edit, get_the_tag_list, get_the_term_list
Source
function get_term_parents_list( $term_id, $taxonomy, $args = array() ) {
$list = '';
$term = get_term( $term_id, $taxonomy );
if ( is_wp_error( $term ) ) {
return $term;
}
if ( ! $term ) {
return $list;
}
$term_id = $term->term_id;
$defaults = array(
'format' => 'name',
'separator' => '/',
'link' => true,
'inclusive' => true,
);
$args = wp_parse_args( $args, $defaults );
foreach ( array( 'link', 'inclusive' ) as $bool ) {
$args[ $bool ] = wp_validate_boolean( $args[ $bool ] );
}
$parents = get_ancestors( $term_id, $taxonomy, 'taxonomy' );
if ( $args['inclusive'] ) {
array_unshift( $parents, $term_id );
}
foreach ( array_reverse( $parents ) as $term_id ) {
$parent = get_term( $term_id, $taxonomy );
$name = ( 'slug' === $args['format'] ) ? $parent->slug : $parent->name;
if ( $args['link'] ) {
$list .= '<a href="' . esc_url( get_term_link( $parent->term_id, $taxonomy ) ) . '">' . $name . '</a>' . $args['separator'];
} else {
$list .= $name . $args['separator'];
}
}
return $list;
}