【问题标题】:Make WordPress show the same page on two different url patterns让 WordPress 在两个不同的 url 模式上显示相同的页面
【发布时间】:2019-01-29 22:28:31
【问题描述】:

我需要让 WordPress 在两个不同的 URL 上显示相同的页面:

https://sitename.com/%postname%/
https://sitename.com/%postname%/tail/

* 我只能使用functions.php

【问题讨论】:

标签: wordpress url url-rewriting permalinks


【解决方案1】:

我使用了一些类似的案例和指南,下面是为我制定的代码:

function tail_rewrite()
{
    add_rewrite_rule('^([^/]*)/tail?', 'index.php?name=$matches[1]', 'top');
    // first parameter for posts: p or name, for pages: page_id or pagename
}

add_action('init', 'tail_rewrite');

不要忘记通过访问设置 > 固定链接来刷新规则 或者在插件激活中使用 flush_rewrite_rules() (不要在每次页面加载时都执行它)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    相关资源
    最近更新 更多