0

The code below is the function for pagination in my wordpress blog. Presently it outputs 7 pages and then the .. last page number.

How can I reduce this number so it shows only 5 pages and then ... last page number?

function emm_paginate_loop($start, $max, $page = 0) {
    $output = "";
    for ($i = $start; $i <= $max; $i++) {
        $output .= ($page === intval($i)) 
            ? "<span class='emm-page emm-current'>$i</span>" 
            : "<a href='" . get_pagenum_link($i) . "' class='emm-page'>$i</a>";
    }
    return $output;
}
2
  • Hi netfreak.. I just checked the codes and yes gap is the default 3. As per the comments, 'range' - Default is 3 (int). The number of page links to show before and after the current page. 'gap' - Default is 3 (int). The minimum number of pages before a gap is replaced with ellipses (...) But it still is quite confusing. Right now the pagination is shown as 'Previous' 1 2 3 4 5 6 7...30 'Next' I'd like to reduce it to 'Previous' 1 2 3 ..30 'Next' Any ideas?? Commented May 19, 2011 at 19:07
  • Fixed it.. changed the default to 2 and it now shows just 5 as I wanted it to Commented May 19, 2011 at 19:13

2 Answers 2

0

I believe you're using 2 custom functions one of them is emm_paginate_loop() you're showing. But i saw that settings for that custom pagination is on function emm_paginate() and specifically "gap":

'gap' - Default is 3 (int). The minimum number of pages before a gap is replaced with ellipses (...).

But that only sets a minimum number...

0

I think you'd be better off using a plugin for this. WP-Paginate gives you this option along with other options that might be useful

Edit
Since a plugin isn't advisable for a mobile site, maybe you could add $range = 5 to the function

function emm_paginate_loop($start, $max, $page = 0, $range = 5) {
    $output = "";
    for ($i = $start; $i <= $max; $i++) {
        $output .= ($page === intval($i)) 
            ? "<span class='emm-page emm-current'>$i</span>" 
            : "<a href='" . get_pagenum_link($i) . "' class='emm-page'>$i</a>";
    }
    return $output;
}
3
  • Chip.. this is for a mobile theme.. so less plugins the better. Commented May 19, 2011 at 19:00
  • I didn't catch that from the original post, my apologies.
    – NW Tech
    Commented May 19, 2011 at 19:24
  • No worries mate.. Cheers and thanks for 'Chip'ing in!! Commented May 20, 2011 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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