Custom Post Type Template Files in WordPress

The has_archive argument is use when registering a custom post type in WordPress, This we have learned in the previous articles. After the enable this argument it will allow you to create an archive template file that will display all of your custom post type entries by default in the Wordperss.

For a custom post type the archive template must be the named in the form of archive-{post-type}.php for custome type post. Let’s suppose that an archive template would be named archive-products.php for your Products custom post type. For display all of your products this archive template is a perfect place. WordPress will also recognize a single template for your post type Entries, just like the archive template.  When you visit a single entry for your custom post type this is the template that is loaded.

For creating the custom posts the single template must be named in the form of single-{posttype}.php named of the tamplate. The name of your singe template products would be the name of single-products.php the name of single tamplate.  The custom posts URL when visiting like that http://example.com/products/zombie-bait, Template would load the single-products.php in WordPress.