简体   繁体   English

具有漂亮URL的Wordpress自定义分页

[英]Wordpress custom pagination with pretty URL's

Currently having slight issues with WP pagination. 目前在WP分页方面存在一些问题。 I've developed a custom theme which requires paging. 我已经开发了一个需要分页的自定义主题。 The paging query is below: 分页查询如下:

<?php if ($query->max_num_pages > 1) : // custom pagination   ?>
                            <?php

                            echo paginate_links(array(
                                    'format' => 'page/%#%',
                                    'current' => max(1, get_query_var('page')),
                                    'total' => $query->max_num_pages,
                                    'prev_text' => __('«'),
                                    'next_text' => __('»'),
                                    'mid_size' => 3
                            ));
                            ?>

Now the paging actually works perfectly if I leave it to the default URL structure of ?page=$page_num however as you can see from the above we are attempting to utilize a slightly prettier URL structure which should have paging set out like /page/$page_num . 现在,如果我将其保留为默认的URL结构?page=$page_num则分页实际上可以正常工作,但是正如您从上面看到的那样,我们正在尝试使用稍微更漂亮的URL结构,该结构应将分页设置为/page/$page_num I have attempted the following .htaccess rewrite however I am still returned a 404 page when navigating to /page/$page_num yet ?page=$page_num still works fine. 我尝试了以下.htaccess重写,但是导航到/page/$page_num时仍然返回404页面,但?page=$page_num仍然可以正常工作。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


RewriteRule ^page/([^/]*)/$ /blog/?page=$1 [L,R=301] 

</IfModule>


# END WordPress

I am at a total loss of the next steps to take. 我完全不知道接下来要采取的步骤。 Any help would be greatly appreciated. 任何帮助将不胜感激。

尝试这个:

RewriteRule ^page/([0-9]+)/?$ /blog/?page=$1 [L]

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

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