get_the_term_list
函数
get_the_term_list ( $post_id, $taxonomy, $before = '', $sep = '', $after = '' )
- 参数
-
-
(int)
$post_id
Post ID.- Required: 是
-
(string)
$taxonomy
Taxonomy name.- Required: 是
-
(string)
$before
Optional. String to use before the terms. Default empty.- Required: 否
- Default: (empty)
-
(string)
$sep
Optional. String to use between the terms. Default empty.- Required: 否
- Default: (empty)
-
(string)
$after
Optional. String to use after the terms. Default empty.- Required: 否
- Default: (empty)
-
(int)
- 返回值
-
- (string|false|WP_Error) A list of terms on success, false if there are no terms, WP_Error on failure.
- 定义位置
-
-
wp-includes/category-template.php
, line 1337
-
wp-includes/category-template.php
- 引入
- 2.5.0
- 弃用
- –
检索一个文章的术语,作为一个具有指定格式的列表。
术语被链接到它们各自的术语列表页。
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[] = '' . $term->name . ''; } /** * 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; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。