<?php
$number = 500; //每页显示500个用户
$paged = (isset($_GET['paged'])) ? $_GET['paged'] : 1;
$offset = ($paged - 1) * $number;
$users = get_users(array('fields' => 'ids', 'orderby' => 'id'));
$query = get_users(array('fields' => 'ids', 'orderby' => 'id', 'offset' => $offset, 'number' => $number));
$total_users = count($users);
$total_query = count($query);
$total_pages = intval($total_users / $number) + 1;

/* 循环出所有符合条件的用户 */
if (!empty($query)) {
    foreach ($query as $uid) {
        // $uid 为用户ID,基于用户ID可以显示各种内容了。
    }
}

/* 分页导航开始 */
if ($total_users > $total_query) {
    echo '<div id="user-pagination">';
    $current_page = max(1, $_GET['paged']);
    echo paginate_links(array(
        'base' => get_pagenum_link(1) . '%_%',
        'format' => '&paged=%#%',
        'current' => $current_page,
        'total' => $total_pages,
        'prev_next' => false, // 是否显示“上一页”,“下一页”
    ));
    echo '</div>';
}
/* 分页导航结束 */

本篇文章相关标签: