Is there a way to create a user page in wordpress

前端 未结 2 740
梦毁少年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:37

    You can create your own templates in wordpress, http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

    0 讨论(0)
  • 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);
    ?>
    <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; ?>
    
    0 讨论(0)
提交回复
热议问题