get_author_posts_url

函数
get_author_posts_url ( $author_id, $author_nicename = '' )
参数
  • (int) $author_id Author ID.
    Required:
  • (string) $author_nicename Optional. The author's nicename (slug). Default empty.
    Required:
    Default: (empty)
返回值
  • (string) The URL to the author's page.
定义位置
相关方法
get_the_author_posts_linkget_the_author_poststhe_author_posts_linkthe_author_postsget_author_rss_link
引入
2.1.0
弃用
-

get_author_posts_url: 此函数返回给定作者的作者档案页的URL。

为提供ID的用户检索到作者页面的URL。

function get_author_posts_url( $author_id, $author_nicename = '' ) {
	global $wp_rewrite;

	$author_id = (int) $author_id;
	$link      = $wp_rewrite->get_author_permastruct();

	if ( empty( $link ) ) {
		$file = home_url( '/' );
		$link = $file . '?author=' . $author_id;
	} else {
		if ( '' === $author_nicename ) {
			$user = get_userdata( $author_id );
			if ( ! empty( $user->user_nicename ) ) {
				$author_nicename = $user->user_nicename;
			}
		}
		$link = str_replace( '%author%', $author_nicename, $link );
		$link = home_url( user_trailingslashit( $link ) );
	}

	/**
	 * Filters the URL to the author's page.
	 *
	 * @since 2.1.0
	 *
	 * @param string $link            The URL to the author's page.
	 * @param int    $author_id       The author's ID.
	 * @param string $author_nicename The author's nice name.
	 */
	$link = apply_filters( 'author_link', $link, $author_id, $author_nicename );

	return $link;
}

常见问题

FAQs
查看更多 >