简体   繁体   English

具有自定义永久链接的Wordpress类别分页

[英]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. 我有一个永久链接结构无法更改的站点,该站点是/blog/%category%/%postname%/并且我正在使用previous_posts_link()next_posts_link()来获取分页链接。 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. 他们使用/blog/events/page/2/生成404页面,而如果我使用/blog/category/events/page/2/ ,则它们可以工作。

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/ )? 因此,理想情况下,我希望/blog/events/page/2/能够正常工作,但如果不能,那么如何获取next_posts_link()输出正确的链接( /blog/category/events/page/2/ )? Mindful of the fact I can't change the permalink structure, for seo purposes, apparently. 考虑到事实上我无法出于SEO的目的更改永久链接结构。

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! 使用插件CPT UI自定义帖子页面模板时遇到了相同的问题,并尝试了很多方法来解决404页面未找到的问题。奇怪的是,解决方案非常简单,我只是将永久链接结构更改为“ Numeric”,所以Voila可以正常工作!

Settings>>Permalinks>>Numeric 设置>>固定链接>>数字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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