Is there a way to create a user page in wordpress

前端 未结 2 793
梦毁少年i
梦毁少年i 2021-01-07 09:08

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 us

2条回答
  •  春和景丽
    2021-01-07 09:40

    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);
    ?>
    
      // Loop through each author $name) : ?>

    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:

    get_queried_object();
    $authid = $curauth->ID;
    ?>
    Email: user_email; ?>
    Website: user_url; ?>
    Name: user_firstname . " " . $curauth->user_lastname; ?>
    Bio: user_description; ?>
    

提交回复
热议问题