get_author_link()
云策文档标注
概述
get_author_link() 是一个已弃用的 WordPress 函数,用于返回或输出作者文章页面的链接。它已被 get_author_posts_url() 替代,自版本 2.1.0 起不建议使用。
关键要点
- 函数已弃用:自 WordPress 2.1.0 起,get_author_link() 被标记为弃用,推荐使用 get_author_posts_url()。
- 功能:返回或输出作者文章页面的 URL,基于作者 ID 和可选作者昵称。
- 参数:接受 $display(布尔值,控制是否输出)、$author_id(整数,必需)和 $author_nicename(字符串,可选)。
- 返回值:返回链接字符串,如果 $display 为 true 则同时输出。
代码示例
function get_author_link($display, $author_id, $author_nicename = '') {
_deprecated_function( __FUNCTION__, '2.1.0', 'get_author_posts_url()' );
$link = get_author_posts_url($author_id, $author_nicename);
if ( $display )
echo $link;
return $link;
}注意事项
- 弃用警告:使用此函数会触发 _deprecated_function() 警告,建议更新代码以避免未来兼容性问题。
- 替代函数:应改用 get_author_posts_url() 来获取作者链接,它更现代且维护良好。
原文内容
Returns or Prints link to the author’s posts.
Description
See also
Parameters
$displayboolrequired$author_idintrequired$author_nicenamestringoptional
Source
function get_author_link($display, $author_id, $author_nicename = '') {
_deprecated_function( __FUNCTION__, '2.1.0', 'get_author_posts_url()' );
$link = get_author_posts_url($author_id, $author_nicename);
if ( $display )
echo $link;
return $link;
}
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Deprecated. Use get_author_posts_url() |
| 1.2.0 | Introduced. |