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.
<div id="pagination">
    <div class="prev"><?php next_posts_link('&larr;') ?></div>
    <div class="pages">
        <?php
            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>
    <div class="next"><?php previous_posts_link('&rarr;') ?></div>
</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.

Screenshot

share|improve this question
add comment

1 Answer

You could try

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

Edit:

In the source code for paginate_links

http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/general-template.php#L1922

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