Create sub single pages

I would like to have the possibility to create “sub single pages” to display detailed content in a custom post type.
Is there a way to generate pages, with a specific template with a URL of this type:

domain.com/custom-post-type-slug/single-slug/sub-single-slug/

Note : I need multiple sub-single pages for each section of my post (content added via ACF). The slug doesn’t need to be dynamic because all of my sections are the same for each post.

Thank you!

2 Answers
2

First, you need to register the custom post type so that it has hierarchy, i.e. a post can have a parent post.

After that, you need to make sure your permalink structure is set to example.com/%postname%/.

Once you have that, you only need to create a child custom post named sub-single-slug and set single-slug as its parent from WordPress backend Editor’s Page Attribute (make sure it’s checked in Screen Options). That’s all. Now your sub-single-slug post will have the link structure as example.com/custom-post-type/single-slug/sub-single-slug/.

For example, I register the custom post type as follows:

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' );

Leave a Comment