WordPress函数:term_description 获取分类描述信息

江河/ 2023年05月10日/ WordPress/ 浏览 718

所谓分类描述信息指的是,如下图所示:



这个字段在一些主题中会显示,或者在SEO的 description 中使用。


函数原型:


term_description( int $term, null $deprecated = null ): string


参数说明:


$term,分类ID。


$deprecated,这个参数已无用,只是为了兼容老代码而保留。


函数源码:


function term_description( $term = 0, $deprecated = null ) {
	if ( ! $term && ( is_tax() || is_tag() || is_category() ) ) {
		$term = get_queried_object();
		if ( $term ) {
			$term = $term->term_id;
		}
	}

	$description = get_term_field( 'description', $term );

	return is_wp_error( $description ) ? '' : $description;
}


使用举例:


<?php echo 'Term Description: ' . term_description( '28','post_tag' ); ?>


发表评论

暂无评论,抢个沙发...

客服 工单