如何解决带有子页面的 Wordpress 自定义帖子类型
我很难找到解决问题的方法。
我们在 wordpress 中有一个名为“商店”的自定义帖子类型,每家商店都有一个唯一的名称,例如“洛杉矶商店,纽约商店”,并且每家商店都有子页面,例如位置、营业时间等。
但不幸的是,为每个商店创建所有子页面是一项艰巨的工作。相反,我们希望为子页面使用一些模板。
我们希望我们的网址结构如下:
sample.com/store/lastore/opening-hours
解决方法
为此,您可以在注册帖子类型时修改 rewrite 参数。下面是一个例子:
$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 );
确保在更改后更新永久链接结构,以便 WordPress 可以重写规则。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。