我在尝试完成一个项目时遇到了一个问题。
- 我将当前的永久链接结构设置为 /%postname%/
- 我创建了自己的函数,只为帖子提供前缀,因此我的帖子被重写为 /{prefix}/%postname%/。
我的问题是我想更改的永久链接pages正如我对帖子所做的那样,我的页面将具有类似 /{prefix}/%pagename%/ 的前缀。
我尝试过但没有成功的方法:
- 重新声明 PAGES 帖子类型并设置重写 slug。
-
尝试添加自定义重写规则作为函数,但它不起作用:
$rewrite_rules += array('mycustomprefix/(.+?)/([0-9]+)/([^/]+)/([^/]+)/?$' =>'index.php?页面名称=$matches[1]',
这可能吗?是否有开发人员遇到过同样的问题?
对于任何感兴趣的人,我已通过以下方式解决了我的问题:
function change_author_permalinks() {
global $wp_rewrite;
// Change the value of the author permalink base to whatever you want here
$wp_rewrite->author_base = '';
// Change the value of the page permalink base to whatever you want here
$wp_rewrite->page_structure = 'static/%pagename%';
$wp_rewrite->flush_rules();
}
add_action('init','change_author_permalinks');
希望这对其他人有帮助,因为我在任何地方都找不到任何帮助。有关可以通过这种方式进行更改的更多信息,请查看http://codex.wordpress.org/Class_Reference/WP_Rewrite http://codex.wordpress.org/Class_Reference/WP_Rewrite
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)