我在尝试完成项目时遇到了问题。
- 我将当前的永久链接结构设置为/%postname%/
- 我创建了自己的函数,只为帖子添加前缀,因此我的帖子将被重写为/{prefix}/%postname%/。
我的问题是我想更改页面的永久链接,就像我对帖子所做的那样,这样我的页面就会有一个像/{prefix}/%pagename%/这样的前缀。
我尝试过但没有成功:
- 重新声明 PAGES 帖子类型并设置重写 slug。
尝试将自定义重写规则添加为函数,但没有成功:
$rewrite_rules += array('mycustomprefix/(.+?)/([0-9]+)/([^/]+)/([^/]+)/?$' =>'索引.php?pagename=$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
关于WordPress 重写仅向页面添加基本前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17613789/