Wizard
Wizard

Reputation: 11265

wordpress paginations url

I made pagination for wordpress, url's is like Address.com/page/1 Address.com/page/2 , but when I click on links I' being transfer to 404.php , my permalinks settings is: /%postname%/. I think that bug is in permalinks, maybe anyone know what is wrong.

Pagination code:

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>';  
    }  
}   

Upvotes: 0

Views: 2732

Answers (1)

Felipe Alameda A
Felipe Alameda A

Reputation: 11799

Here is an example that works using WP functions. You can make it a function or try it at the end of each page to replace the function in your question:

global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array( 'base'    => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                            'format'  => '?paged=%#%',
                            'current' => max( 1, get_query_var( 'paged' ) ),
                            'total'   => $wp_query->max_num_pages,
                            'end_size'=> 1,
                            'mid_size'=> 10 ) );

Upvotes: 1

Related Questions