函数文档

get_author_feed_link()

💡 云策文档标注

概述

get_author_feed_link() 函数用于获取指定作者的 feed 链接,支持自定义 feed 类型,如 RSS2 或 Atom。它根据网站的固定链接设置生成链接,并可通过过滤器进行修改。

关键要点

  • 函数返回指定作者所有文章的 feed 链接,参数包括作者 ID 和可选的 feed 类型(如 'rss2'、'atom')。
  • 如果未指定 feed 类型,则使用 get_default_feed() 的默认值。
  • 函数内部处理固定链接结构:无固定链接时使用查询字符串,有固定链接时通过 get_author_posts_url() 构建路径。
  • 提供 author_feed_link 过滤器,允许开发者自定义生成的链接。
  • 相关函数包括 get_author_posts_url()、get_default_feed()、trailingslashit() 等。

代码示例

// 返回作者 ID 为 2 的默认 feed 链接
echo get_author_feed_link( '2', '' );

📄 原文内容

Retrieves the feed link for a given author.

Description

Returns a link to the feed for all posts by a given author. A specific feed can be requested or left blank to get the default feed.

Parameters

$author_idintrequired
Author ID.
$feedstringoptional
Feed type. Possible values include 'rss2', 'atom'.
Default is the value of get_default_feed() .

Return

string Link to the feed for the author specified by $author_id.

Source

function get_author_feed_link( $author_id, $feed = '' ) {
	$author_id           = (int) $author_id;
	$permalink_structure = get_option( 'permalink_structure' );

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

	if ( ! $permalink_structure ) {
		$link = home_url( "?feed=$feed&author=" . $author_id );
	} else {
		$link = get_author_posts_url( $author_id );
		if ( get_default_feed() === $feed ) {
			$feed_link = 'feed';
		} else {
			$feed_link = "feed/$feed";
		}

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

	/**
	 * Filters the feed link for a given author.
	 *
	 * @since 1.5.1
	 *
	 * @param string $link The author feed link.
	 * @param string $feed Feed type. Possible values include 'rss2', 'atom'.
	 */
	$link = apply_filters( 'author_feed_link', $link, $feed );

	return $link;
}

Hooks

apply_filters( ‘author_feed_link’, string $link, string $feed )

Filters the feed link for a given author.

Changelog

Version Description
2.5.0 Introduced.

User Contributed Notes