get_the_term_list()
get_the_term_list( int $id, string $taxonomy, string $b…
get_the_term_list( int $id, string $taxonomy, string $before = ”, string $sep = ”, string $after = ” )
以指定格式的列表形式检索文章的术语。
Retrieve a post’s terms as a list with specified format.
以指定格式的列表形式检索文章的术语。
Retrieve a post’s terms as a list with specified format.
目录锚点:#参数#返回#源码#笔记
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $id | (int) | 必需 | 邮政编码。 |
| $taxonomy | (string) | 必需 | 分类法名称。 |
| $before | (string) | 可选 | 在列表之前。 |
| $sep | (string) | 可选 | 用这个把物品分开。 |
| $after | (string) | 可选 | 在列表之后。 |
返回(Return)
(string|false|WP_Error)一个成功术语列表,如果没有术语,则为false,如果失败则为WP|u Error。
源码(Source)
/**
* Retrieve a post's terms as a list with specified format.
*
* @since 2.5.0
*
* @param int $id Post ID.
* @param string $taxonomy Taxonomy name.
* @param string $before Optional. Before list.
* @param string $sep Optional. Separate items using this.
* @param string $after Optional. After list.
* @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
*/
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[] = '' . $term->name . '';
}
/**
* Filter 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;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.5.0 | wp-includes/category-template.php:1281 | 2 | 6 |
笔记(Notes)
基本示例
返回HTML列表
您可以将此功能与strip_tags功能一起使用,以打印未链接的术语列表:
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!