php - wordpress 自定义 add_rewrite_rule 不适用于分页
问题描述
我的 functions.php 文件中有以下函数。它的作用是让我可以一起使用 2 个自定义分类法。
function nfh_custom_rewrite_rules() {
add_rewrite_rule('^product_cat/(.*)/bins/(.*)?', 'index.php?product_cat=$matches[1]&bins=$matches[2]', 'top');
}
add_action('init', 'nfh_custom_rewrite_rules');
所以我可以有这样的网址:
mysite.com/product_cat/homeware/bins/promo/
..这很好用
我遇到的问题是分页似乎不起作用。我一进入第 2 页:
mysite.com/product_cat/homeware/bins/promo/page/2/
它只是抛出一个未找到的错误。
任何帮助将不胜感激
解决方案
我没有测试,但检查如下。这可能会有所帮助。
function nfh_custom_rewrite_rules() {
add_rewrite_rule('^product_cat/(.*)/bins/(.*)/page/([0-9]{1,})/?', 'index.php?product_cat=$matches[1]&bins=$matches[2]&paged=$matches[3]', 'top');
}
add_action('init', 'nfh_custom_rewrite_rules');
推荐阅读
- python - pip install trains 失败
- java - 组件树为空,无法添加任何组件
- java - kotlin(jvm,js)中的多维稀疏数组?
- python - 以相同的结构抓取多个页面
- django-admin - 所选组在管理面板中不可见
- swiftui - 在 RealityKit 中删除多个实体
- javascript - 以 DOM Vue 方式用 div 包裹 iframe
- javascript - 有没有办法返回一个类型是数组中的一项
- functional-programming - 如何在 F# 中正确实现 reduce 函数
- r - 为什么我的 R 工作室不显示箱线图?