父页面的子页面与自定义帖子类型名称相同导致404 [英] Child page of parent page with same name as custom post type causes 404

查看:65
本文介绍了父页面的子页面与自定义帖子类型名称相同导致404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这个问题上进行了广泛的搜索,发现其他人也有类似的问题,但是没有适合我的解决方案.

I've searched extensively on this issue and have found others with similar problems, but no solutions that work in my case.

情况是这样的:
*我已经创建了一个带有自定义'events'的自定义帖子类型.
*我创建了一个带有事件"标签的页面.
*我已将子页面添加到事件页面(第一级子页面)
*我已将子页面添加到那些子页面(二级子页面)中
*永久链接结构设置为/%category%/%postname%/
*我没有使用任何插件或自定义代码来处理自定义帖子类型.
*当我导航到/events/时,可以使用pages.php模板很好地加载页面.
*当我导航到/events/first-level-child/时,我得到了404.
*当我导航到/events/first-level-child/second-level-child/时,使用page.php模板可以正常加载页面.
*当我导航到/events/category-name/时,使用archive.php模板可以正常加载页面.

The situation is this:
* I have created a custom post type with the slug 'events'.
* I have created a page with the slug 'events'.
* I have added child pages to the events page (first-level children)
* I have added child pages to those child pages (second-level children)
* The permalink structure is set to /%category%/%postname%/
* I am not using any plugins or custom code to handle custom post types.
* When I navigate to /events/, the page loads fine using the pages.php template.
* When I navigate to /events/first-level-child/ I get a 404.
* When I navigate to /events/first-level-child/second-level-child/ the page loads fine using the page.php template.
* When I navigate to /events/category-name/ the page loads fine using the archive.php template.

问题是尝试查看与自定义帖子类型相同的子页面的第一级子页面时出现404.

The problem is the 404 I get when trying to view a first-level child page of the page with the same slug as that of a custom post type.

我不能选择重命名两个弹头,以使其与众不同.我需要找到一种方法来使子页面和类别均能按事​​件"页面的预期工作.我无法在.htaccess文件中为子页面创建自定义重定向,因为客户端必须能够自己创建子页面.

It is not an option for me to rename either of the slugs so that they're different. I need to find a way to get both child pages and categories to work as expected for the Events page. I cannot create custom redirects in the .htaccess file for the child pages as the client must be able to create them themselves.

是否有一些方法可以修改WordPress生成的重写规则以实现我的目标?还是有一个我可以利用的插件会有所帮助?我猜WordPress希望第二个uri段是一个类别名称.如果找不到类别,是否有办法让它查找具有该名称的页面?

Is there some way to modify the rewrite rules generated by WordPress to achieve my goal? Or is there maybe a plugin that I could utilize that would help? I'm guessing that WordPress expects the second uri segment to be a category name. Is there a way to have it look for pages with that name if no category is found?

推荐答案

这里的解决方案是为自定义帖子类型定义一个自定义分类法,该自定义分类与该帖子类型本身的分类符不同.

Looks like the solution here is to define a custom taxonomy for the custom post type with a slug different than the slug for the post type itself.

在这种情况下,帖子类型的标签为事件",分类标准的标签为事件/类别".这样做可以显示子页面以及帖子的类别.

In this case the slug for the post type is 'events' and the slug for the taxonomy is 'events/category'. Doing this allows the child pages to display as well as the categories for the post.

这篇关于父页面的子页面与自定义帖子类型名称相同导致404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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