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 have a custom pagination function in functions.php. If I'm at the URL: http://mysite.com/tag/dogs, the Next link currently just contains /page/2.

How can I make it so it will look like /tag/dogs/page/2?

Here is the function I am using: (originally posted here)

function pagination( $query, $baseURL = '' ) {
    if ( ! $baseURL ) $baseURL = get_bloginfo( 'url' );
    $page = $query->query_vars["paged"];
    if ( !$page ) $page = 1;
    $qs = $_SERVER["QUERY_STRING"] ? "?".$_SERVER["QUERY_STRING"] : "";
    // Only necessary if there's more posts than posts-per-page
    if ( $query->found_posts > $query->query_vars["posts_per_page"] ) {
        echo '<ul class="paging">';
        // Previous link?
        if ( $page > 1 ) {
            echo '<li class="previous"><a href="'.$baseURL.'page/'.($page-1).'/'.$qs.'">« previous</a></li>';
        }
        // Loop through pages
        for ( $i=1; $i <= $query->max_num_pages; $i++ ) {
            // Current page or linked page?
            if ( $i == $page ) {
                echo '<li class="active">'.$i.'</li>';
            } else {
                echo '<li><a href="'.$baseURL.'page/'.$i.'/'.$qs.'">'.$i.'</a></li>';
            }
        }
        // Next link?
        if ( $page < $query->max_num_pages ) {
            echo '<li><a href="'.$baseURL.'page/'.($page+1).'/'.$qs.'">next »</a></li>';
        }
        echo '</ul>';
    }
}

Any help would be greatly appreciated. Thanks!

share|improve this question
    
You are going to have to post your custom function code here. We cannot tell you how to fix your code without first seeing it... –  Brady May 16 '11 at 15:40
    
See above for the update. –  Zoolander May 16 '11 at 16:00

1 Answer 1

up vote 2 down vote accepted

Why can you not use the core functions previous_posts_link()/next_posts_link() or posts_nav_link(), all of which already account for the taxonomy archive context?

EDIT:

I think I understand your question now. You want pagination links, rather than previous/next page links.

WordPress also has a native function for pagination links: paginate_links() (Codex ref).

Here's how I use this function in my own Theme:

function oenology_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('page','%#%'),
        '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' ) );

    echo paginate_links( $pagination );
}
share|improve this answer
    
Thanks for your response. This could work, but how would I add links like 1, 2, 3, 4, 5? –  Zoolander May 16 '11 at 16:18
    
Why would you need to? The native WordPress functions are intended to handle the pagination. –  Chip Bennett May 16 '11 at 16:55
    
See edited answer: I just realized that you want paginated links, rather than previous/next page links. –  Chip Bennett May 16 '11 at 16:59

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.