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 the Reverie theme as a framework for my sites and I'm having an issue with using a function to create variable posts per page plus having the arrows for the paging to work. I used the variable function to fix a 404 error I was getting when I paged to the last page of a category. The numbers work fine, goes to each page as they should be if I try and use the previous/next arrows, though they are linked, nothing happens. (I currently have the prev_next set to false since they aren't working and it's a live site).

The code from the Reverie theme for pagination:

function reverie_pagination() {
global $wp_query;

$big = 999999999; // This needs to be an unlikely integer

// For more options and info view the docs for paginate_links()
// http://codex.wordpress.org/Function_Reference/paginate_links
$paginate_links = paginate_links( array(
    'base' => str_replace( $big, '%#%', get_pagenum_link($big) ),
    'current' => max( 1, get_query_var('paged') ),
    'total' => $wp_query->max_num_pages,
    'mid_size' => 5,
    'prev_next' => False,
    'prev_text' => __('«'),
    'next_text' => __('»'),
    'type' => 'list'
) );

// Display the pagination if more than one page is found
if ( $paginate_links ) {
    echo '<div class="reverie-pagination">';
    echo $paginate_links;
    echo '</div><!--// end .pagination -->';

And the code I'm using to limit/change posts per page:

function limit_posts_per_page() {
if ( is_category() )
    return 12;
    return 13; // default: 13 posts per page

add_filter('pre_option_posts_per_page', 'limit_posts_per_page');

And the code from my category-loop template:

// Let's retrieve 10 posts per page and ensure that paginating works
$page = get_query_var('paged');
$cat = get_category($cat);
query_posts('cat='. $cat->cat_ID.'&paged='. $page); 

<?php while (have_posts()) : the_post(); ?>

// loop stuff
<?php endwhile; // End the loop ?>

<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( function_exists('reverie_pagination') ) { reverie_pagination(); } else if ( is_paged() ) { ?>
<nav id="post-nav">
<div class="post-previous"><?php next_posts_link( __( '&larr; Older posts', 'reverie' ) ); ?></div>
<div class="post-next"><?php previous_posts_link( __( 'Newer posts &rarr;', 'reverie' ) ); ?></div>
<?php } ?>

I guess I don't understand why the function that limits posts_per_page would be "breaking" the prev/next arrows? Any help or being pointed in the correct direction would be appreciated. The arrows were working before I added this function (except for the 404 error I mentioned on the last page).

share|improve this question
add comment

Your Answer


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

Browse other questions tagged or ask your own question.