I use this code for my custom paging :
global $wpdb, $table_prefix, $current_user;
get_currentuserinfo();
$umail = $current_user->user_email;
$paged = $wpdb->get_results("SELECT * FROM {$table_prefix}comments WHERE comment_author_email = '$umail'");
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$pages = COUNT($paged);
$pages = ceil($pages / 2);
$querystring = "";
foreach ($_GET as $key => $value) {
if ($key != "page") $querystring .= "$key=$value&";
}
// Pagination
for ($i = 1; $i <= $pages; $i++) {
echo "<a " . ($i == $page ? "class="selected" " : "");
echo "href="?{$querystring}page=$i";
echo "">$i</a> ";
}
This code paginate my comments look like this :
1 2 3 4 5 6 7 8 9 10 11
How can change code to get paginate look like this:
1 2 3 … 11
Thanks for any help.
Instead of the loop at the bottom, use WordPress’s
paginate_links()
:You can play around with some of https://codex.wordpress.org/Function_Reference/paginate_links to get the appearance the way you want. Specifically, the
end_size
andmid_size
will help you to determine the number of page numbers that show, as in your example (1 2 3 … 11).If you want something really powerful, you can check out my Boone’s Pagination plugin: http://teleogistic.net/2011/05/new-wordpress-plugin-boones-pagination/ (shameless plug!), though it may be too much for your use case 🙂