如何像档案页面一样列出用户页面上的10个用户并具有导航功能

时间:2013-05-12 作者:Batman

如何像归档页面一样列出注册用户?如何在用户名上创建指向用户配置文件页面的链接?

请查看链接http://postimg.org/image/9wkp6kfib/

<?php
/*
Template Name: Registered Users
*/
?>
<?php get_header(); ?>

<div class="art-contentLayout">
 <div class="art-content">
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <div class="art-Post">
   <div class="art-Post-tl"></div>
   <div class="art-Post-tr"></div>
   <div class="art-Post-bl"></div>
   <div class="art-Post-br"></div>
   <div class="art-Post-tc"></div>
   <div class="art-Post-bc"></div>
   <div class="art-Post-cl"></div>
   <div class="art-Post-cr"></div>
   <div class="art-Post-cc"></div>
   <div class="art-Post-body">
    <div class="art-Post-inner art-article">
     <h2 class="art-PostHeader"> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(\'Permanent Link to %s\', \'kubrick\'), the_title_attribute(\'echo=0\')); ?>">Registered Users </a> </h2>
     <table class="tut">
      <thead>
       <tr>
        <th><b>Poza</b></th>
        <th><b>Name</b></th>
        <th><b>Inregistrat</b></th>
        <th><b>Nume</b></th>
        <th><b>User Level</b></th>
        <th><b>User Role</b></th>
        <th><b>Vezi Profil</b></th>
       </tr>
      </thead>
      <tbody id="the-list" class="list:user">
       <?php 
          $wp_user_search = $wpdb->get_results("SELECT ID, display_name FROM $wpdb->users ORDER BY ID");
          foreach ( $wp_user_search as $userid ) {
            $user_id = (int) $userid->ID;
            $user_info = get_userdata($user_id);
                                                $user_picture =  get_avatar($userid->ID, 40);
            $formid = $user_info->formid;
            $user = new WP_User( $user_id );
            echo \'<th>\' . $user_picture .  \'</th>\';
            echo \'<th>\' . $user_info->display_name . \'</th>\';
            echo \'<th>\' . $user_info->user_registered . \'</th>\';
            echo \'<th>\' . $user_info->nickname . \'</th>\';
            echo \'<th>\' . $user_info->user_level . \'</th>\';
            echo \'<th>\'; if ( !empty( $user->roles ) && is_array( $user->roles ) ) { foreach ( $user->roles as $role ) echo $role; } echo \'</th>\';
            echo \'<th>\' . $userid->ID . \'</th>\';
                                                echo \'</tr>\';
          } 
                                        ?>
      </tbody>
      <tfoot>
       <tr>
        <th><b>Poza</b></th>
        <th><b>Name</b></th>
        <th><b>Inregistrat</b></th>
        <th><b>Nume</b></th>
        <th><b>User Level</b></th>
        <th><b>User Role</b></th>
        <th><b>Vezi Profil</b></th>
       </tr>
      </tfoot>
     </table>
    </div>
    <div class="cleared"></div>
   </div>
  </div>
  <?php endwhile; endif; ?>
 </div>
 <div class="art-sidebar1">
 </div>
</div>
<div class="cleared"></div>
<?php get_footer(); ?>

1 个回复
SO网友:Angela

首先,可以使用WP_User_Query而不是WP_User类来查找用户列表。我写了一个片段来演示这一点。我还没有测试过,所以你可能想重写整个过程。请签出此日志以供参考http://mattvarone.com/wordpress/list-users-with-wp_user_query/ 还有法典http://codex.wordpress.org/Class_Reference/WP_User_Query#Pagination_Parameters

$per_page = 10;
$offset = isset($_GET[\'offset\']) ? $_GET[\'offset\'] : 0;

$args = array(
    \'role\'      => \'Subscriber\',
\'number\'  => 999999      
);
$user_query = new WP_User_Query( $args );
$total_pages = count($user_query->get_results()) / $per_page;

$args = array(
    \'role\'      => \'Subscriber\',
    \'orderby\'   => \'display_name\',
    \'number\'    => $per_page,
    \'offset\'    => $offset
);
$user_query = new WP_User_Query( $args );
$all_users  = $user_query->get_results();

foreach($all_users as $user) {
    $user_info = get_userdata($user->ID);
    //Format your output here
    echo $user->email, $user->first_name;
}

echo paginate_links( array(
\'base\'          => $base,
\'format\'        => \'&offset=%#%\',
\'prev_text\' => __(\'&laquo; Previous\'),
\'next_text\' => __(\'Next &raquo;\'),
\'total\'         => $total_pages,
\'current\'   => $offset
));

结束