WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
<div id="pagination">
    <div class="prev"><?php next_posts_link('&larr;') ?></div>
    <div class="pages">
            global $wp_query;
            $big = 9999;
            echo paginate_links(array(
                'base' => str_replace($big, '%#%', get_pagenum_link($big)),
                'format' => '?paged=%#%',
                'total' => $wp_query->max_num_pages,
                'current' => max(1, get_query_var('paged')),
                'show_all' => false,
                'end_size' => 1,
                'mid_size' => 5,
                'prev_next' => false,
                'prev_text' => 'Prev',
                'next_text' => 'Next',
                'type' => 'list'
    <div class="next"><?php previous_posts_link('&rarr;') ?></div>

Hi, I have a pagination loop setup and am choosing to display both the numbers and the prev / next links. However, I'm trying to figure out how I can end the #'s at the most recent 5 articles [1,2,3,4,5] instead of it carrying over to [1,2,3,4,5,6,7]. How would I go about ending it at the most recent 5 articles published on my blog?

"I'm just wanting to edit the div-class pages part so it just ends at 5." - If that makes any sense.


share|improve this question

You could try

'total' => min(5,$wp_query->max_num_pages),


In the source code for paginate_links


the links are displayed in a loop with $n = 1; $n <= $total; $n++ and since %#% is replaced with $n my idea is to limit the number of displayed pagelinks by restricting $total to the minimum of 5 and $wp_query->max_num_pages. Hope this helps ;-)

share|improve this answer
Could you explain why this might solve the problem, and have you tested the solution? – s_ha_dum Feb 26 '13 at 20:12
sure: I looked at the source code for paginate_links and noticed the loop $n = 1; $n <= $total; $n++ and since %#% is replaced with $n, I thought it might limit the number of displayed pagelinks by restricting $total to the minimum of 5 and $wp_query->max_num_pages. At least this was my idea ;-) – birgire Feb 26 '13 at 20:43
... as part of your answer. This answer was flagged as "low quality due to length and content" by the software, which I am sure you want to avoid. It is best to provide explanation along with the raw (suggested) solution. – s_ha_dum Feb 26 '13 at 20:52
ok thanks @s_ha_dum, I just registered few weeks ago so I'm still learning the rules here ;-) I will update the answer. – birgire Feb 26 '13 at 20:58
Thanks, that worked! :3 I couldn't find anything in the codex about this sort of thing. – Monstr92 Feb 28 '13 at 21:17

Your Answer


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.