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 followed the very simple tutorial that's on this page: http://wp.tutsplus.com/tutorials/wordpress-pagination-a-primer/ (Scroll down to "A Better Solution") - He makes it seem so simple, and it works in that the pagination links are there and the URL changes in the address bar, but it doesn't actually update when clicking on 2 or 3..

Site - chrisayreswebdev.com/besh

I know I'm missing something, just not sure what. Any ideas? Thanks!

EDIT: functions.php:

function paginate() {
global $wp_query; 
$total_pages = $wp_query->max_num_pages;  

if ($total_pages > 1){  

 $current_page = max(1, get_query_var('paged'));  

 echo paginate_links(array(  
        'base' => get_pagenum_link(1) . '%_%',  
        'format' => 'page/%#%',  
        'current' => $current_page,  
        'total' => $total_pages,
     ));  
}
}

index.php:

        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                <div class="post">
                <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                 <?php the_title(); ?></a></h1>
                <h4>Posted on <?php the_time('F jS, Y') ?></h4>
                <div class="horzline"></div>
                <p><?php the_content(__('(more...)')); ?></p>
                </div>
            <?php endwhile; else: ?>
            <p><?php _e("Sorry, we couldn't find the post you are looking for."); ?></p>

        <?php endif; ?>
        <?php paginate(); ?>  
share|improve this question
1  
Please paste your code - Its hard to guess what exactly you're missing without code. –  amit Aug 21 '12 at 15:09
    
Downvote for not posting relevant code, thus rendering the question impossible to answer. –  Chip Bennett Aug 21 '12 at 15:11
    
I know - I figured since I posted the link to the tutorial and used the exact code on there, that it would be sufficient. I've edited my post to include the code. –  user Aug 21 '12 at 16:24
add comment

1 Answer

I suspect your problem is here:

'base' => get_pagenum_link(1) . '%_%'

You're passing 1 to get_pagenum_link(), rather than the actual page number. Try passing your previously determined $current_page instead:

'base' => get_pagenum_link( $current_page ) . '%_%'

Note, I use this as base:

'base' => @add_query_arg('paged','%#%')

Edit

I tried your suggestion as well as the '@add_query_arg' that you use and neither seemed to actually update the pagination to the next set of posts. The url changes to "/besh/page/2" but the posts don't change and the page number stays at 1. It's as if I'm missing something entirely from my code.

The best I can do is to give you my full, working code:

/**
 * Paginate Archive Index Page Links
 */
function oenology_get_paginate_archive_page_links( $type = 'plain', $endsize = 1, $midsize = 1 ) {
    global $wp_query, $wp_rewrite;  
    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;

    // Sanitize input argument values
    if ( ! in_array( $type, array( 'plain', 'list', 'array' ) ) ) $type = 'plain';
    $endsize = (int) $endsize;
    $midsize = (int) $midsize;

    // Setup argument array for paginate_links()
    $pagination = array(
        'base' => @add_query_arg('paged','%#%'),
        'format' => '',
        'total' => $wp_query->max_num_pages,
        'current' => $current,
        'show_all' => false,
        'end_size' => $endsize,
        'mid_size' => $midsize,
        'type' => $type,
        'prev_text' => '&lt;&lt;',
        'next_text' => '&gt;&gt;'
    );

    if( $wp_rewrite->using_permalinks() )
        $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );

    if( !empty($wp_query->query_vars['s']) )
        $pagination['add_args'] = array( 's' => get_query_var( 's' ) );

    return paginate_links( $pagination );
}
share|improve this answer
    
I tried your suggestion as well as the '@add_query_arg' that you use and neither seemed to actually update the pagination to the next set of posts. The url changes to "/besh/page/2" but the posts don't change and the page number stays at 1. It's as if I'm missing something entirely from my code. –  user Aug 21 '12 at 16:52
    
See updated answer. The best I can do is share my full, working code. –  Chip Bennett Aug 21 '12 at 16:56
    
I tried a direct C&P into my functions.php and changed the call on the index.php and nothing. The page numbers went away, there was not HTML code for the pagination output anywhere on my index. I fiddled with it and couldn't come up with a working solution. Not sure if I'm just missing something somewhere else in my theme (built from scratch). For now, I'm just going to hard code a "View All Posts" button that links to my archive page. Thanks man –  user Aug 21 '12 at 19:00
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.