get_the_term_list()获取一篇文章的所有分类并且已HTML形式输出

目录

描述

Returns an HTML string of taxonomy terms associated with a post and given taxonomy. Terms are linked to their respective term listing pages.

get_the_term_list() 描述

用法

 <?php get_the_term_list$id$taxonomy$before$sep$after ?> 

get_the_term_list() 用法

参数

$id

(int) (必填) Post ID

默认值: None

$taxonomy

(string) (必填) Name of taxonomy

默认值: None

$before

(string) (可选) Leading text

默认值: empty string

$sep

(string) (可选) String to separate tags

默认值: empty string

$after

(string) (可选) Trailing text

默认值: empty string

get_the_term_list() 参数

历史

  • 添加于 版本: 2.5.0

get_the_term_list() 历史

源文件

get_the_term_list() 函数的代码位于 wp-includes/category-template.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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[] = '';
	}

	/**
	 * 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;
}

get_the_term_list() 源文件

相关