首先,您需要注册自定义帖子类型,使其具有层次结构,即一篇帖子可以有一个父帖子。
之后,您需要确保将permalink结构设置为example.com/%postname%/
.
一旦你有了它,你只需要创建一个名为sub-single-slug
和设置single-slug
作为WordPress后端编辑器的父级Page Attribute (确保已签入Screen Options
). 仅此而已。现在您的sub-single-slug
帖子的链接结构如下example.com/custom-post-type/single-slug/sub-single-slug/
.
例如,我注册自定义帖子类型如下:
function wpse_register_custom_post_type() {
$labels = array(
"name" => __( \'custom post type\', \'text-domain\' ),
"singular_name" => __( \'custom post types\', \'text-domain\' ),
);
$args = array(
"label" => __( \'custom post type\', \'text-domain\' ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_menu" => true,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => true,
"rewrite" => array( "slug" => "custom_post_type", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail", "custom-fields", "page-attributes" ),
"taxonomies" => array( "category", "post_tag" ),
);
register_post_type( "custom_post_type", $args );
}
add_action( \'init\', \'wpse_register_custom_post_type\' );