0

Is this possible?

I am trying to get pagination working on my pages and single pages. It seems like it's working, as it recognizes how many pages there are and shows the URL. The problem: the URL is wrong!

Functions.php:

function pagination_bar( $query_wp ) 
{
    $pages = $query_wp->max_num_pages;
    $big = 999999999; // need an unlikely integer
    if ($pages > 1)
    {
        $page_current = max(1, get_query_var('paged'));
        echo paginate_links(array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => $page_current,
            'total' => $pages,
        ));
    }
}

The query:

$the_query = new WP_Query(  array( 'posts_per_page' => 25,
                                           'paged' => $paged
                                            ) ); 
        $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

The HTML:

    <nav class="pagination">
<?php pagination_bar( $the_query ); ?>

What URL I am getting when pagination is activated and clicked upon the next page:

https://mywebsitename.com/my_postorpagename/page/3/

What I want to get:

https://mywebsitename.com/page/3/

Question: (how) can I do this?

  • The URL you get is correct. If you remove the post/page name how would WordPress know which post/page the page refers to? The URL you want would point to page 3 of your home page, which doesn't exist. – freejack Jun 13 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.