【问题标题】:Custom post type permalink shows blog/ in the single page自定义帖子类型永久链接在单个页面中显示 blog/
【发布时间】:2023-04-10 04:57:01
【问题描述】:

我创建了一个自定义帖子类型,它永久链接将 blog/ 显示到单个页面中, 例如:www.example.com/blog/event/wine-tasting/

我需要将此 blog/ 从单页 URL 中删除,它应该是这样的, www.example.com/event/wine-tasting/

【问题讨论】:

  • 您使用的是什么 CMS?或者你在哪里做这个?您是否使用 .htaccess 来重写 URL?需要更多说明。
  • 我正在使用 wordpress CMS,默认的自定义帖子永久链接使用 blog/ URL 生成。不在functions.php中使用任何重写规则,也不通过.htaccess重定向。

标签: wordpress blogs permalinks


【解决方案1】:

我做了一些研究并想出了这篇文章:

当您注册自定义帖子类型时,您必须指定 重写规则不应以现有的 URL 结构为前缀。

简而言之,这意味着您的 register_post_type 调用中的这一行:

'rewrite' => array('slug' => 'projects'),应该变成这个:

'rewrite' => array('slug' => 'projects','with_front' => false), 为 更多信息,请查看 codex 条目中的 rewrite 参数 register_post_type

编辑:只需确保在更新代码后刷新 通过访问设置 > 永久链接重写规则。否则你会 仍然看到旧链接。 - 安德烈奥

如果你被另一个问题难倒了here - 索菲亚:

WordPress.org Topic

TutsPlus

Another Question

【讨论】:

    猜你喜欢
    • 2013-04-10
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多