将帖子的术语检索为具有指定格式的列表。
原型
get_the_term_list( int $id, string $taxonomy, string $before = '', string $sep = '', string $after = '' )
参数
$id
(int)
(Required)
帖子ID。
$taxonomy
(string)
(Required)
分类名称。
$before
(string)
(Optional)
在列表之前。
$sep
(string)
(Optional)
使用此单独的项目。
$after
(string)
(Optional)
列表后。
返回值
(string|false|WP_Error)
成功条款列表,如果没有条款,则为false
源文件
路径:wp-includes/category-template.php
<?php
...
function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
$terms = get_the_terms( $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 filter name, `$taxonomy`, refers
* to the taxonomy slug.
*
* @since 2.5.0
*
* @param array $links An array of term links.
*/
$term_links = apply_filters( "term_links-{$taxonomy}", $links );
return $before . join( $sep, $term_links ) . $after;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_the_term_list/