获取指定作者的文章列表网址
描述
获取指定ID(参数 $author_id)的作者的文章列表网址。
用法
<?php get_author_posts_url( $author_id, $author_nicename ); ?>
参数
$author_id
(integer) (必填) ID of the author whose URL should be retrieved.
默认值: None
$author_nicename
(string) (可选) User nicename.
默认值: empty
返回值
(string)
The URL to the author’s page.
示例
Display the link of the author page for the author of the current post
<a href=“<?php echo get_author_posts_url( get_the_author_meta( ‘ID’ ) ); ?>“><?php the_author(); ?></a>
源文件
get_author_posts_url() can be located in wp-includes/author-template.php
/**
* 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;
}
相关
the_author(),
get_the_author(),
the_author_link(),
get_the_author_link(),
the_author_meta(),
get_the_author_meta(),
the_author_posts(),
get_the_author_posts(),
the_author_posts_link(),
get_author_posts_url(),
get_the_modified_author(),
the_modified_author(),
wp_dropdown_users(),
wp_list_authors()
- 原文:http://codex.wordpress.org/Function_Reference/get_author_posts_url