get_author_posts_url()获取指定作者的文章列表网址

目录

描述

获取指定ID(参数 $author_id)的作者的文章列表网址。

get_author_posts_url() 描述

用法

<?php get_author_posts_url$author_id$author_nicename ); ?>

get_author_posts_url() 用法

参数

$author_id

(integer) (必填) ID of the author whose URL should be retrieved.

默认值: None

$author_nicename

(string) (可选) User nicename.

默认值: empty

get_author_posts_url() 参数

返回值

(string) 

The URL to the author's page.

get_author_posts_url() 返回值

示例

Display the link of the author page for the author of the current post

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php the_author(); ?></a>

get_author_posts_url() 示例

源文件

get_author_posts_url() can be located in wp-includes/author-template.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve the URL to the author page for the user with the ID provided.
 *
 * @since 2.1.0
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @return string The URL to the author's page.
 */
function get_author_posts_url($author_id, $author_nicename = '') {
	global $wp_rewrite;
	$auth_ID = (int) $author_id;
	$link = $wp_rewrite->get_author_permastruct();

	if ( empty($link) ) {
		$file = home_url( '/' );
		$link = $file . '?author=' . $auth_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 ) );
	}

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

get_author_posts_url() 源文件

相关