javascript - 自定义帖子类型子帖子中子网址的 WordPress 自定义 JS 路由
问题描述
我添加了一个 JS 路由器 ( Navigo.js ) 并喜欢在 Costum Post Type 帖子上使用它。但我无法让它工作。
我喜欢上班的url struktur是这样的:
/[CTP]/[post_title]/[JS router]
function paper_post_type() {
register_post_type('paper',
[
'labels' => array (
'name' => 'Paper',
'menu_name' => 'Paper',
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'hierarchical' => true,
'rewrite' => true,
'has_archive' => false
]
);
}
add_action('init', 'paper_post_type');
add_action('init', function() {
add_rewrite_rule(
'^paper/([^/]+)/?$',
'index.php?paper=$matches[1]',
'top'
);
});
解决方案
这有效:
add_action('init', function() {
add_rewrite_rule('^paper/([^/]*)/', 'index.php?paper=$matches[1]', 'top');
});
推荐阅读
- transparency - Imagemagick 堆栈图像与透明度重叠
- ansible - 即使文件不存在,Ansible 2.4 uri 模块也会下载文件 (1K) - url 返回 404 错误
- vba - 对正负值求和 vba userform
- latex - 有没有办法在 Latex 中显示代码文件的某些行?
- javascript - 为什么日志中的 F.prototype 属性不一致
- javascript - 根据状态更改按钮的 className 无法正常工作
- python - 保持 python 调度程序脚本在 Windows 上运行
- c++ - 恒定时间构建/重新解释兼容数据的向量?
- pandas - 如何在蚁群优化中绘制 ROC 曲线(基本蚂蚁矿工)
- hyperledger-composer - Hyperledger Composer ACL 条件中绑定变量的描述