如何为自定义帖子创建单个模板

I create a custom post type add following code in theme's functions.php

function  cptarchivePost_init() {
    $args = array(
      'label' => 'Archive Post',
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => array('slug' => 'cpt_archive_post'),
        'query_var' => true,
        'menu_icon' => 'dashicons-video-alt',
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'trackbacks',
            'custom-fields',
            'comments',
            'revisions',
            'thumbnail',
            'author',
            'page-attributes',)
        );
    register_post_type( 'cpt_archive_post', $args );
}
add_action( 'init', 'cptarchivePost_init' );

add_action( 'init', 'create_cpt_archive_category', 0 );
function create_cpt_archive_category() {
    register_taxonomy(
        'cpt_archive_category',
        'cpt_archive_post',
        array(
            'labels' => array(
                'name' => 'Category',
                'add_new_item' => 'Add Category',
                'new_item_name' => "New Category"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true
        )
    );
}

and create a file/template in theme with name single-cpt_archive_post.php but still the post using index.php template

can anyone help how can I create single template for custom post

First you have to create your CPT. In our example the name of CPT is "projects".

 function custom_taxonomies(){

        //Custom post type(Projects)
        $labels = array(
            'name' => _x('Projects', 'post type general name'),
            'singular_name' => _x('Project', 'post type singular name'),
            'add_new' => _x('Add new Project', 'member'),
            'add_new_item' => __('Add new Project'),
            'edit_item' => __('Edit'),
            'new_item' => __('New Project'),
            'view_item' => __('View'),
            'search_items' => __('Search Project'),
            'not_found' =>  __('No Projects found!'),
            'not_found_in_trash' => __('No Projects in the trash!'),
            'parent_item_colon' => ''
        );
        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'menu_position' => null,
            'taxonomies' => array('post_tag'),
            'supports' => array('title','thumbnail','editor','excerpt','author'),
            'menu_icon' => 'dashicons-feedback',
            'has_archive' => true
        );
        register_post_type('projects',$args);

        $labels = array(
            'name' => _x( 'Category', 'taxonomy general name' ),
            'singular_name' => _x( 'Category', 'taxonomy singular name' ),
            'search_items' =>  __( 'Search category' ),
            'all_items' => __( 'All categories' ),
            'parent_item' => __( 'Parent category' ),
            'parent_item_colon' => __( 'Parent category' ),
            'edit_item' => __( 'Edit category' ),
            'update_item' => __( 'Update category' ),
            'add_new_item' => __( 'Add new category' ),
            'new_item_name' => __( 'Category name' ),
        );

        register_taxonomy( 'projects_tax', array( 'projects' ), array(
            'hierarchical' => true,
            'labels' => $labels,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'projects_category' ),
        ));



    }

    add_action( 'init', 'custom_taxonomies', 0 );

And then you Create your file single-projects.php

After that refresh your permalinks.