get_term_feed_link

函数
get_term_feed_link ( $term, $taxonomy = '', $feed = '' )
参数
  • (int|WP_Term|object) $term The ID or term object whose feed link will be retrieved.
    Required:
  • (string) $taxonomy Optional. Taxonomy of `$term_id`.
    Required:
    Default: (empty)
  • (string) $feed Optional. Feed type. Possible values include 'rss2', 'atom'. Default is the value of get_default_feed().
    Required:
    Default: (empty)
返回值
  • (string|false) Link to the feed for the term specified by `$term` and `$taxonomy`.
定义位置
相关方法
get_tag_feed_linkget_category_feed_linkget_search_feed_linkget_author_feed_linkget_term_link
引入
3.0.0
弃用
-

get_term_feed_link: 这个函数检索特定术语的RSS提要的URL。它需要两个参数:术语的ID和该术语所属的分类法名称。它以字符串形式返回feed URL。

检索一个术语的feed链接。

返回一个指向给定术语中所有文章的feed链接。可以请求一个特定的feed,或者留空以获得默认的feed。

function get_term_feed_link( $term, $taxonomy = '', $feed = '' ) {
	if ( ! is_object( $term ) ) {
		$term = (int) $term;
	}

	$term = get_term( $term, $taxonomy );

	if ( empty( $term ) || is_wp_error( $term ) ) {
		return false;
	}

	$taxonomy = $term->taxonomy;

	if ( empty( $feed ) ) {
		$feed = get_default_feed();
	}

	$permalink_structure = get_option( 'permalink_structure' );

	if ( ! $permalink_structure ) {
		if ( 'category' === $taxonomy ) {
			$link = home_url( "?feed=$feed&cat=$term->term_id" );
		} elseif ( 'post_tag' === $taxonomy ) {
			$link = home_url( "?feed=$feed&tag=$term->slug" );
		} else {
			$t    = get_taxonomy( $taxonomy );
			$link = home_url( "?feed=$feed&$t->query_var=$term->slug" );
		}
	} else {
		$link = get_term_link( $term, $term->taxonomy );
		if ( get_default_feed() == $feed ) {
			$feed_link = 'feed';
		} else {
			$feed_link = "feed/$feed";
		}

		$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
	}

	if ( 'category' === $taxonomy ) {
		/**
		 * Filters the category feed link.
		 *
		 * @since 1.5.1
		 *
		 * @param string $link The category feed link.
		 * @param string $feed Feed type. Possible values include 'rss2', 'atom'.
		 */
		$link = apply_filters( 'category_feed_link', $link, $feed );
	} elseif ( 'post_tag' === $taxonomy ) {
		/**
		 * Filters the post tag feed link.
		 *
		 * @since 2.3.0
		 *
		 * @param string $link The tag feed link.
		 * @param string $feed Feed type. Possible values include 'rss2', 'atom'.
		 */
		$link = apply_filters( 'tag_feed_link', $link, $feed );
	} else {
		/**
		 * Filters the feed link for a taxonomy other than 'category' or 'post_tag'.
		 *
		 * @since 3.0.0
		 *
		 * @param string $link     The taxonomy feed link.
		 * @param string $feed     Feed type. Possible values include 'rss2', 'atom'.
		 * @param string $taxonomy The taxonomy name.
		 */
		$link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy );
	}

	return $link;
}

常见问题

FAQs
查看更多 >