简体   繁体   中英

Wordpress Category Pagination With Custom Permalinks

I have a site with a permalink structure I can't change, which is /blog/%category%/%postname%/ and I'm using previous_posts_link() and next_posts_link() to get pagination links. They work fine on date/all posts but not on category pages.

It's down to those links not having the right permalinks. They use /blog/events/page/2/ which results in a 404 page, whereas if I use /blog/category/events/page/2/ , they work.

So, ideally I'd like /blog/events/page/2/ to work but if not then how can I get next_posts_link() to output the right links ( /blog/category/events/page/2/ )? Mindful of the fact I can't change the permalink structure, for seo purposes, apparently.

Here's the loop query:

        <?php 
        global $query_string;

        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

        parse_str( $query_string, $args );

        $args['paged'] = $paged;

        query_posts($args); ?>

        <?php if (have_posts()) : ?>

        <div id="post-results">

        <div class="pagination">

            <?php if (get_previous_posts_link()): ?>
                <span><?php previous_posts_link( 'Recent posts' ); ?></span>
            <?php endif; ?>

            <?php if (get_next_posts_link()): ?>
                <span><?php next_posts_link( 'Previous posts' ); ?></span>
            <?php endif; ?>

        </div>

        ... rest of loop

Thanks.

I had the same issue while working with plugin CPT UI custom post page template, and tried a lot to resolve the 404 page not found issue, Strangely the solution was quite simple, I just changes the permalink structure to "Numeric" and Voila it works!

Settings>>Permalinks>>Numeric

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM