有没有办法在wordpress中创建用户页面 [英] Is there a way to create a user page in wordpress
问题描述
在 Wordpress 中有一个 author.php 模板文件,您可以使用它来显示作者信息.我想知道是否有办法创建一个模板文件来显示用户信息(任何角色),即使他们不是任何帖子的作者,而是注册用户.类似于 http://domain.com/user/some_name
a.创建一个名为 members.php 的模板并将这样的代码片段放在该文件中:
<块引用>全局$wpdb;$query = "SELECT ID from $wpdb->users";$author_ids = $wpdb->get_results($query);$users = 数组();foreach($author_ids 作为 $author) {//获取用户数据$curauth = get_userdata($author->ID);//获取作者页面的链接$link = "/member/" .$curauth->user_nicename;$name = $curauth->display_name;$users[$link] = $name;}分类($用户);?><ol>//遍历每个作者<?phpforeach($users as $link => $name) :?><li><a href="<?php echo $link; ?>"title="<?php echo $name; ?>"><?php回声 $name;?></a><?php endforeach;?></ol>
B.使用上述模板创建一个名为 members 的 wordpress 页面.此页面将列出所有博客注册用户以及一个页面/member/user-name
.
c.现在创建您的 author.php 模板,使用如下代码片段显示用户信息:
get_queried_object();$authid = $curauth->ID;?>电子邮件:<?php echo $curauth->user_email;?>网站:<?php echo $curauth->user_url;?>名称: <?php echo $curauth->user_firstname ."".$curauth->user_lastname;?>生物:<?php echo $curauth->user_description;?>
In Wordpress there is an author.php template file that you can use to display author information. I am wondering if there is a way to create a template file to display a users information (any role), even if they are not an author to any post, but is a registered user. Something like http://domain.com/user/some_name
a. Create a template called members.php and put code snippet like this on that file:
global $wpdb; $query = "SELECT ID from $wpdb->users"; $author_ids = $wpdb->get_results($query); $users = array(); foreach($author_ids as $author) { // Get user data $curauth = get_userdata($author->ID); // Get link to author page $link = "/member/" . $curauth->user_nicename; $name = $curauth->display_name; $users[$link] = $name; } asort($users); ?> <ol> // Loop through each author <?php foreach($users as $link => $name) : ?> <li> <a href="<?php echo $link; ?>" title="<?php echo $name; ?>"><?php echo $name; ?></a> </li> <?php endforeach; ?> </ol>
b. Create a wordpress page called members using above template. This page will list all blog registered users with a ink to a page /member/user-name
.
c. Now create your author.php template displaying user information with code snippet like this:
<?php
$curauth = $wp_query->get_queried_object();
$authid = $curauth->ID;
?>
Email: <?php echo $curauth->user_email; ?>
Website: <?php echo $curauth->user_url; ?>
Name: <?php echo $curauth->user_firstname . " " . $curauth->user_lastname; ?>
Bio: <?php echo $curauth->user_description; ?>
这篇关于有没有办法在wordpress中创建用户页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!