Wordpress:如何将其父级添加到自定义帖子类型子页面作为slug?

时间:2016-06-28 14:29:22

标签: wordpress

设置'分层' =>如果是自定义帖子类型并将父级分配给具有此自定义帖子类型的页面,则会抛出404.可以使其工作吗?

预期结果:http://example.com/parent-page/page-title/

这适用于Wordpress常规页面,但不适用于自定义帖子类型(未找到404)。

提前致谢!

1 个答案:

答案 0 :(得分:2)

由于我刚刚注意到您希望永久链接结构与页面完全相同,因此您可以在注册帖子类型时修改$args = array( 'labels' => $labels, 'hierarchical' => true, // just to get parent child relationships with your custom post [but you already knew this part] 'description' => 'Your custom post type description here', 'has_archive' => false, 'rewrite' => array('slug' => '/'), // we rewrite the slug to the root url so that it has no post type prefix 'with_front' => false, // This is optional but just in case your posts are set to /blog/post-name this will make it /post-name for your custom post type 'capability_type' => 'post', 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ) ); register_post_type( 'post_type', $args ); 参数。以下是如何使其像页面结构一样的示例:

{{1}}

另外,请确保在进行这些更改后更新永久链接结构,以便Wordpress可以重写规则。