WordPress 重写仅向页面添加基本前缀

标签 wordpress url-rewriting permalinks

我在尝试完成项目时遇到了问题。

  1. 我将当前的永久链接结构设置为/%postname%/
  2. 我创建了自己的函数,只为帖子添加前缀,因此我的帖子将被重写为/{prefix}/%postname%/。

我的问题是我想更改页面的永久链接,就像我对帖子所做的那样,这样我的页面就会有一个像/{prefix}/%pagename%/这样的前缀。

我尝试过但没有成功:

  1. 重新声明 PAGES 帖子类型并设置重写 slug。
  2. 尝试将自定义重写规则添加为函数,但没有成功:

    $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/

相关文章:

javascript - 单击某个项目后加载帖子详细信息页面

jquery - 如何更改 Twenty Twenty 插件中的前后标签?

grails - Grails g:paginate标记和自定义URL

asp.net - 复杂重定向 : HTTP to HTTPS + port on localhost and naked domain to www,(本地主机除外)

regex - 使用另一个 get params 重写查询字符串

php - 如何使permlink大写为小写

wordpress - WordPress的永久链接无法正常工作

php - 如何在显示 WordPress 帖子的 PHP 中循环 while 语句?

php - ACF Repeater 字段返回包含中继器计数的字符串

.htaccess - 如何在禁用永久链接结构的情况下使用 add_rewrite_rule 函数?