You must ensure that the post type is registered with has_archive
property set to true
Look at codex example, replace ‘Books’ with ‘Products’
function codex_custom_init() {
$labels = array(
'name' => 'Books', 'singular_name' => 'Book',
'add_new' => 'Add New', 'add_new_item' => 'Add New Book',
'edit_item' => 'Edit Book', 'new_item' => 'New Book',
'all_items' => 'All Books', 'view_item' => 'View Book',
'search_items' => 'Search Books', 'not_found' => 'No books found',
'not_found_in_trash' => 'No books found in Trash', 'parent_item_colon' => '',
'menu_name' => 'Books'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'book' ),
'capability_type' => 'post',
'has_archive' => true, // <- this arg must be true
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type( 'book', $args );
}
add_action( 'init', 'codex_custom_init' );
If you are sure ‘has_archive’ is true, in your theme root create a file named products.php
that should be someting like:
<?php get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<div style="float: right; margin: 10px">
<?php the_post_thumbnail( array( 100, 100 ) ); ?>
</div>
<strong>Name: </strong><?php the_title(); ?><br />
</header>
<div class="entry-content"><?php the_content(); ?></div>
</article>
<?php endwhile; ?>
</div>
</div>
<?php get_footer(); ?>
Than create a file named archive-products.php
and put there simply:
get_template_part('products');
Than create a file named single-products.php
and put there simply:
// yes, exactly the same thing
get_template_part('products');