My page displays a list of WordPress users. For pagination, I have used the function paginate_links. This inserts a list onto my page e.g.
- page 2
- page 3
- page 4
(screenshot). And each list item is a link to a new page which displays the paginated results, e.g.
- http://example.com/sample-page/page/2/
- http://example.com/sample-page/page/3/
- http://example.com/sample-page/page/4/
My code is below.
Is there a way to use paginate_links() to just insert the list, yet refrain from inserting links into each item, and refrain from creating new pages?
The motivation for this is that I want the list to display, but I want to add my own link to each list item. Each link will be one that makes an AJAX call to my server, fetches new data, and displays it all on the same page. When a visitor clicks one of these links, I do not want him to be redirected to a different page, and I do not want a new page to be created--both seem to be default behavior for paginate_links().
My existing code
<?php
$number = 10; // Update this according to your needs. Users perpage
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$offset = ($paged - 1) * $number;
$users = get_users();
$args = array(
'orderby' => 'login',
'order' => 'ASC',
'offset' => $offset,
'number' => $number,
'count_total' => false,
);
$query = get_users($args);
$total_users = count($users);
$total_query = count($query);
$total_pages = intval($total_users / $number) + 1;
echo $total_users . ' ' . $total_query . ' ' . $total_pages;
if ($total_users > $total_query) {
?>
<div id="pagination" class="clearfix">
<span class="pages">Pages:</span>
<?php
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%/',
'current' => $current_page,
'total' => $total_pages,
'prev_next' => false,
'type' => 'list',
));
?>
</div>
<?php
}