[resolved] How do I make a template for items with custom post type? (3 posts)

  1. lynkei
    Posted 3 years ago #

    I have created a custom post type using the following code.

    /* Product Post Type */
        add_action('init', 'Product_post_type_init');
        function Product_post_type_init() {
          $labels = array(
            'name' => _x('Product', 'post type general name'),
            'singular_name' => _x('Product', 'post type singular name'),
            'add_new' => _x('Add New', 'Product'),
            'add_new_item' => __('Add New Product'),
            'edit_item' => __('Edit Product'),
            'new_item' => __('New Product'),
            'view_item' => __('View Product'),
            'search_items' => __('Search Products'),
            'not_found' =>  __('No Products found'),
            'not_found_in_trash' => __('No Products found in Trash'),
          $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true, //false - to hide from the admin area menu
            'rewrite' => true,
            'query_var' => true,
            'capability_type' => 'post',
            'hierarchical' => true, //allow parent pages
            'show_in_nav_menus' => false,
            'menu_position' => 1000,
    	'taxonomies' => array('category'),
            'supports' => array(

    What I'm now trying to do is create a template for all posts that use that post type. How do I go about doing this.

    From what I've read I came up with naming the file single-Product.php but that didn't work. What am I doing wrong?
    Thanks in advance for your help.

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    You'll want to include has_archive in your $args


    archive-Product.php would be the template for your overall archive (like index.php for normal posts)

    single-Product.php is the template for single post view

    you'd also need to flush rewrite rules after setting up your CPT (visiting your permalinks page and hitting save works)

  3. lynkei
    Posted 3 years ago #

    Thanks a lot Rev. Voodoo. That's what it took.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.