get_the_term_list( int $post_id, string $taxonomy, string $before = '', string $sep = '', string $after = '' )
Retourne les termes d'un poste sous forme de liste au format spécifié.
Paramètres
$post_id
(int)requisId du poste.
$taxonomy
(string)requisNom de la taxonomie.
$before
(string)optionnelChaîne à utiliser avant les termes.
Valeur par défaut : ''
$sep
(string)optionnelChaîne à utiliser entre les termes.
Valeur par défaut : ''
$after
(string)optionnelChaîne à utiliser après les termes.
Valeur par défaut : ''
Retourne
(string|false|WP_Error) Une liste de termes, false s'il n'y a aucuns termes ou WP_Error si échec.
Déclaration et structure de la fonction get_the_term_list()
get_the_term_list()
est déclarée dans le fichier wp-includes/category-template.php
à la ligne 1338 :
function get_the_term_list( $post_id, $taxonomy, $before = '', $sep = '', $after = '' ) {
$terms = get_the_terms( $post_id, $taxonomy );
if ( is_wp_error( $terms ) ) {
return $terms;
}
if ( empty( $terms ) ) {
return false;
}
$links = array();
foreach ( $terms as $term ) {
$link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $link ) ) {
return $link;
}
$links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
}
/**
* Filters the term links for a given taxonomy.
*
* The dynamic portion of the hook name, `$taxonomy`, refers
* to the taxonomy slug.
*
* Possible hook names include:
*
* - `term_links-category`
* - `term_links-post_tag`
* - `term_links-post_format`
*
* @since 2.5.0
*
* @param string[] $links An array of term links.
*/
$term_links = apply_filters( "term_links-{$taxonomy}", $links ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
return $before . implode( $sep, $term_links ) . $after;
}
Fonctions utilisées par get_the_term_list()
get_the_terms()
Retourne les termes d'une taxonomie attachés à un poste.
esc_url()
Vérifie et nettoie une URL.
get_term_link()
Génère un permalien pour l'archive d'un terme.
apply_filters()
Appel les fonctions qui ont été attaché à un filtre (hook).
is_wp_error()
Vérifie si la variable est une erreur WordPress.
Hook utilisé par get_the_term_list()
term_links-taxonomy
Filtre les liens de terme pour une taxonomie donnée.
Où est utilisée la fonction get_the_term_list()
dans le CMS WordPress
Exemples
echo get_the_term_list( $post->ID, 'people', 'People: ', ', ' );
get_the_term_list( $post->ID, 'styles', '<ul class="styles"><li>', ',</li><li>', '</li></ul>' );
Sources
Codex WordPress : get_the_term_list()
Autres fonctions dans le même fichier : wp-includes/category-template.php