我想为我设置自定义后类型staff
作为about-us
页面比如孩子:WordPress的母公司页
从example.com/staff/john-doe
转到example.com/about-us/john-doe
目前我已经想尽可能发布在Google和Stack上无济于事,我可以找到的最佳解决方案是将以下内容添加到我的functions.php
,该框架添加了一个元框,使我可以为各个员工手动设置父页面。
add_action('admin_menu', function() { remove_meta_box('pageparentdiv', 'chapter', 'normal');});
add_action('add_meta_boxes', function() { add_meta_box('chapter-parent', 'Part',
'chapter_attributes_meta_box', 'chapter', 'side', 'high');});
function chapter_attributes_meta_box($post) {
$post_type_object = get_post_type_object($post->post_type);
if ($post_type_object->hierarchical) {
$pages = wp_dropdown_pages(array('post_type' => 'part', 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0));
if (! empty($pages)) {
echo $pages;
} // end empty pages check
} // end hierarchical check.
}
然而,随着'rewrite' => array('slug' => 'about-us'),
结合了这一点似乎导致example.com/about-us/about-us/john-doe
和不正确的它既不example.com/staff/about-us/john-doe
工作!
首先,我想知道是否有解决上述问题的解决方案,其次是有更好的方法来实现这一点,并且可能不必手动为每个单独的帖子选择父页面,而是整个自定义帖子键入设置为页面的子项?
如果我在这方面取得进展,我一定会更新!
不要再让你困惑了,但试图做到这一点的动机是导航相关的,所以我的菜单系统会自动调整。如果这不是问题,我会简单地使用重写,并有一个自定义菜单,每次移动或添加页面时都需要更新!当你有多个CPT时,这显然不理想。
怎么样使用自定义页面模板,而不是一个CPT,然后只设置,页面模板到子页面? – 2014-10-01 15:35:42
about-us页面正在使用自定义页面模板,但是在查看关于我们不是父母的单个员工页面时会出现URL问题,因为默认情况下,页面不能成为父母。 – Giles 2014-10-01 15:42:08