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;
}
link|improve this question

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?? – Sledge81 May 19 '11 at 19:07
Fixed it.. changed the default to 2 and it now shows just 5 as I wanted it to – Sledge81 May 19 '11 at 19:13
feedback

2 Answers

up vote 0 down vote accepted

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...

link|improve this answer
feedback

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;
}
link|improve this answer
Chip.. this is for a mobile theme.. so less plugins the better. – Sledge81 May 19 '11 at 19:00
I didn't catch that from the original post, my apologies. – Chip May 19 '11 at 19:24
No worries mate.. Cheers and thanks for 'Chip'ing in!! – Sledge81 May 20 '11 at 16:39
feedback

Your Answer

 
or
required, but never shown

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