函数原型:
get_author_posts_url( int $author_id, string $author_nicename = '' ): string
获取置顶用户ID的用户的作者页面的URL。
参数说明:
$user_id:用户ID
$author_nicename:用户 slug 。
函数源码:
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 ) );
}
$link = apply_filters( 'author_link', $link, $author_id, $author_nicename );
return $link;
}
包含钩子:
apply_filters( 'author_link', string $link, int $author_id, string $author_nicename )
使用举例:
显示当前文章作者的作者页面链接。
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php echo esc_attr( get_the_author() ); ?>"><?php the_author(); ?></a>
-
WordPress函数:国际化 _ex 展示带上下文的翻译字符串WordPress函数:国际化 _ex 展示带上下文的翻译字符串
-
WordPress函数:国际化 _n 翻译字符串,可以区分单数复数WordPress函数:国际化 _n 翻译字符串,可以区分单数复数
-
WordPress函数:国际化 _nx 翻译字符串,_n + _xWordPress函数:国际化 _nx 翻译字符串,_n + _x
-
WordPress函数:_n_loop 在 pot 文件中注册字符串WordPress函数:_n_loop 在 pot 文件中注册字符串
-
WordPress函数:国际化 _nx_noop 在 pot 中注册字符串WordPress函数:国际化 _nx_noop 在 pot 中注册字符串
-
WP Multilang WordPress翻译插件WP Multilang插件的主要功能是提供多语言支持,使用户能够创建多语言版本的网站,满足不同语言用户的需求。
暂无评论,抢个沙发...