WordPress重写仅将基本前缀添加到页面 [英] Wordpress rewrite add base prefix to pages only

查看:76
本文介绍了WordPress重写仅将基本前缀添加到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试完成项目时遇到问题.

I have a problem I've encountered when trying to finish a project.

  1. 我将当前的永久链接结构设置为/%postname%/
  2. 我发挥了自己的功能,即仅给帖子添加前缀,因此我的帖子被重写为/{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:

  1. 重新声明PAGES帖子类型并设置重写标记.
  2. 试图将自定义重写规则添加为函数,但没有用:

  1. Re-declare the PAGES post type and set a rewrite slug.
  2. 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重写仅将基本前缀添加到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆