WordPress为所有人创建一个用户个人资料页面

时间:2018-07-01 05:18:54

标签: wordpress getusermedia

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

user是本机Author而非自定义帖子类型

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

https://myexample.com/user/joe/ ----将显示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'); 
?>

有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

我使用下面的代码来创建自定义用户个人资料页面,希望对其他人有帮助

<?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; 
?>
相关问题