Is there a way to create a user page in wordpress
In Wordpress there is an author.php template file that you can use to display author info开发者_如何学编程rmation. 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; ?>
You can create your own templates in wordpress, http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates
精彩评论