由於我剛剛注意到您需要的頁面結構完全像頁面,您可以在註冊帖子類型時修改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的可以重寫規則。
這個永久鏈接結構是否可以運行:'example.com/post-type/parent-slug/child-slug'?或者你是否不希望永久鏈接中的帖子類型? – JoeMoe1984
我不希望帖子類型在永久鏈接:( – Maxi
我剛剛更新了我的答案,現在它清楚:) – JoeMoe1984