web建站教程
     
  1. 首页
  2. 前端UI组件库
  3. AI项目和框架
  4. 前端知识
  5. AI应用
  6. IT知识
  7. ComfyUI插件
  8. 地图大全
  9. 休息站

wordpress如何获取指定作者页面的链接url

989 ℃

如何利用wordpress​中的函数获取指定作者页面的链接url,下面web建站小编给大家简单介绍一下关于get_author_posts_url()​函数的基本用法!

函数原型:

get_author_posts_url( int $author_id, string $author_nicename = '' ): string

参数说明:

$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做时间列表,比如2024年1月文章列表

wordpress利用mysql获取指定分类下的文章

WordPress如何重置admin密码

WordPress教程如何自动删除文章中图片宽高样式

wordpress建站如何快速提交和优化您的网站(IndexNow插件)?

标签: get_author_posts_url wordpress技巧 wordpress获取作者url

上面是“wordpress如何获取指定作者页面的链接url”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_4404.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 首页 > wordpress
扣子空间 – 免费全能AI办公智能体
Trae:新一代免费的AI编程工具
上一篇:
下一篇:
x 打工人ai神器
x 扫一扫打开藏历小程序

打开微信“扫一扫”查看今日藏历!