问题描述
尝试完成项目时遇到问题.
I have a problem I've encountered when trying to finish a project.
- 我将当前的永久链接结构设置为/%postname%/
- 我发挥了自己的功能,即仅给帖子添加前缀,因此我的帖子被重写为/{prefix}/%postname%/.
我的问题是我想像对待帖子一样更改页面的永久链接,以便我的页面具有/{prefix}/%pagename%/之类的前缀.
My problem is that I want to change the permalink of the pages as I did with the posts so my pages will have a prefix like /{prefix}/%pagename%/.
我尝试过但没有奏效的东西:
What I tried and didn't work:
- 重新声明PAGES帖子类型并设置重写标记.
-
试图将自定义重写规则添加为函数,但没有用:
- Re-declare the PAGES post type and set a rewrite slug.
Tried adding a custom rewrite rule as a function but it didn't work:
$ rewrite_rules + = array('mycustomprefix/(.+?)/([0-9] +)/([^/] +)/([^/] +)/?$'=>'index .php?pagename = $ matches [1]',
$rewrite_rules += array('mycustomprefix/(.+?)/([0-9]+)/([^/]+)/([^/]+)/?$' =>'index.php?pagename=$matches[1]',
这可能吗?那里有没有遇到相同问题的开发人员?
Is this possible? Are there any developers out there who encountered the same issue?
推荐答案
对于感兴趣的任何人,我已通过以下方式解决了问题:
For anybody interested, I've fixed my issue in the following manner:
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
Hope this helps others as I couldn't find any help for this anywhere. For morer information on what you can change this way, check out http://codex.wordpress.org/Class_Reference/WP_Rewrite
这篇关于WordPress重写仅将基本前缀添加到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!