代码之家  ›  专栏  ›  技术社区  ›  superUntitled

从post id获取作者信息

  •  40
  • superUntitled  · 技术社区  · 14 年前

    或者甚至来自post id的author id。我正在尝试返回单个post页(post循环之外)的侧边栏中的author meta(author page link和avatar)。最好的方法是什么?我正在使用一个自定义函数(见下文)返回post id,但不确定接下来要调用什么函数。

    function this_post_id() {
      global $wp_query;
      $thePostID = $wp_query->post->ID;
      return $thePostID;
    }
    
    2 回复  |  直到 6 年前
        1
  •  82
  •   Charlesthk    8 年前

    我想出来了。

    <?php $author_id=$post->post_author; ?>
    <img src="<?php the_author_meta( 'avatar' , $author_id ); ?> " width="140" height="140" class="avatar" alt="<?php echo the_author_meta( 'display_name' , $author_id ); ?>" />
    <?php the_author_meta( 'user_nicename' , $author_id ); ?> 
    
        2
  •  39
  •   ssourav    7 年前

    如果您希望它在循环之外,那么使用下面的代码。

    <?php
    $author_id = get_post_field ('post_author', $cause_id);
    $display_name = get_the_author_meta( 'display_name' , $author_id ); 
    echo $display_name;
    ?>
    
        3
  •  1
  •   Emerson Thompson    4 年前
    <?php
      $field = 'display_name';
      the_author_meta($field);
    ?>
    

    $field 参数包括:

    • 管理颜色
    • 目标
    • 显示\u名称
    • 叽叽喳喳
    • 昵称
    • 每页的插件数
    • 富库编辑
    • 语法\u突出显示
    • 用户激活密钥
    • 用户描述
    • 用户电子邮件
    • 用户名
    • 用户登录
    • 用户名
    • 用户密码
    • 用户\u已注册
    • 用户状态
    • 用户url