Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

Instead of the loop at the bottom, use WordPress's paginate_links():

$pagination = paginate_links(array(
    'total' => $pages,
    'current' => $page
));
echo $pagination;

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 and mid_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 :)

share|improve this answer
    
Not work, error : 'Parse error: syntax error, unexpected T_DOUBLE_ARROW in ' –  Nulled Mar 16 '12 at 18:29
2  
@Nulled It was missing the array statement, fixed now (as soon as a moderator approves my edit anyways). –  Kit Sunde Mar 17 '12 at 22:47
    
Oops, my bad. Thanks, @KitSunde –  Boone Gorges Mar 17 '12 at 23:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.