gpt4 book ai didi

php - 自定义帖子类型的WordPress页面父级

转载 作者:搜寻专家 更新时间:2023-10-31 22:02:26 24 4
gpt4 key购买 nike

我正试图将我的自定义post typestaff设置为页面的子页面,例如:
about-us转到example.com/staff/john-doe
我目前已经在google和stack上尝试了所有可能的帖子,但都没有成功,我可以找到的壁橱解决方案是将下面的内容添加到我的example.com/about-us/john-doe中,这将添加一个元框,使我能够为个别员工手动设置父页面。

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.
}

然而,当将其与 functions.php结合时,似乎会导致 'rewrite' => array('slug' => 'about-us'),并且如果没有它,则 example.com/about-us/about-us/john-doe都无法正常工作!
首先,我想知道是否有解决上述问题的方法,其次,是否有更好的方法来实现这一点,并且可能不必为每个帖子手动选择父页面,而是将整个自定义帖子类型设置为页面的子页面?
如果我在这方面有任何进展,我一定会更新的!
不要再迷惑你了,但是尝试这样做的动机与导航有关,所以我的菜单系统会自动调整。如果这不是一个问题,我会简单地使用重写,并有一个自定义菜单,我需要更新每一次页面被移动或添加!这显然是不理想的,当你有多个CPT。

最佳答案

这可能与register_post_type()调用有关。您的重写可能需要如下所示:

'rewrite' => array('slug' => 'about-us', 'with_front' => false )

“with_front”部分应该删除您当前准备发布的任何内容。例如,如果在permalinks部分中,您正在使用staff(看起来您正在使用staff,虽然这只是一个猜测,因为我看不到您的设置)来准备所有的帖子,with_front会忽略它。
有了这个解决方案,您也不需要额外的元框函数。
别忘了在这个更改之后访问permalink页面,以确保permalinks被刷新并且您没有401s…

关于php - 自定义帖子类型的WordPress页面父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26127811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com