【问题标题】:WordPress create a user profile page for everyoneWordPress为每个人创建一个用户个人资料页面
【发布时间】:2018-12-09 18:19:25
【问题描述】:

我正在尝试为所有 WordPress 用户创建一个用户个人资料页面,以便访问者可以看到每个用户的个人资料及其基本信息。

user 是原生 Author 不是自定义帖子类型

例如:我的自定义用户个人资料链接

https://myexample.com/user/joe/---- 将显示乔的个人资料

https://myexample.com/user/jhon/---- 将显示 jhon 的个人资料

但我的代码仅适用于管理员/作者有什么方法可以显示

<?php 
$ID             = the_author_meta('ID');
$first_name     = the_author_meta('first_name'); 
$last_name  = the_author_meta('last_name');
$user_fullname = $first_name . ' ' . $last_name; 
$nickname       = the_author_meta('nickname'); 
$branch_code    = the_author_meta('branch_code'); 
$index_no       = the_author_meta('index_no'); 
$sp_designation = the_author_meta('sp_designation'); 
$description    = the_author_meta('description'); 
$mobile_number  = the_author_meta('mobile_number'); 
$user_email     = the_author_meta('user_email'); 
?>

谁能帮我解决这个问题?

【问题讨论】:

    标签: wordpress getusermedia


    【解决方案1】:

    我使用波纹管代码制作自定义用户个人资料页面希望这对其他人有所帮助

    <?php 
    
    $curauth = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
    
        $first_name     = $curauth-> first_name;
        $last_name  = $curauth-> last_name;
        $nickname       = $curauth-> nickname;
        $branch_code    = $curauth-> branch_code;
        $index_no       = $curauth-> index_no;
        $sp_designation = $curauth-> sp_designation;
        $mobile_number = $curauth-> mobile_number;
        $user_email     = $curauth-> user_email;
        $user_fullname = $first_name . ' ' . $last_name; 
    ?>
    

    【讨论】:

      【解决方案2】:

      您可以使用 get_user_meta 函数。 像这样:

      <?php echo get_user_meta($user_id, 'first_name', TRUE); ?>
      

      https://developer.wordpress.org/reference/functions/get_user_meta/

      【讨论】:

      • no user 是原生 Author 不是自定义帖子类型
      • 什么会通过$user_id
      • 用户 ID。您可以使用“get_current_user_id()”获取当前用户id。
      • get_current_user_id() 将显示当前登录的用户。但我需要我当前访问的用户 slug
      猜你喜欢
      • 2012-06-30
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 2013-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多