0

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

1
  • What of 123 steps have you been followed? Disable? Change?
    – Max Yudin
    Commented Mar 6, 2018 at 18:17

1 Answer 1

0

You can also use (page) templates for custom post types, see this link.

Just add this to you template file:

Template Post Type: your-post-type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.