How to Build a Template for a Custom Post Type in WordPress Twenty Fifteen
By default, custom post types in WordPress use the single.php template in your theme — that is, unless you create a specific template for your custom post type. You may find the regular WordPress single.php template limiting for your post type. This depends on the type of content you want to include and whether you want to apply different formats and styles for your custom post type with HTML and CSS markup.
After you add the code to build a simple Generic Content custom post, the Generic Content menu on the WordPress Dashboard appears. Choose Generic Content → Add New, and then publish a new post with some content for testing. For example, add a new Generic Content type with a Test title and a test slug. Because the Generic Content type doesn’t have a specific template yet, it uses the single.php template, and resulting posts look no different from the standard.
If a Not Found page appears when you try to access a new custom post type entry, reset your permalink settings. Choose Settings → Permalinks on the Dashboard and then click the Save Changes button. This forces WordPress to reset the permalinks for your site and add the new custom post type permalink formats.
To build a template specific for the Generic Content post type, add a new single-posttype.php template (posttype is the first argument passed to the register_post_type function). For this example, the template file specific to the Generic Content post type is single-generic-content.php. Any modifications made to this template file are shown only for instances of the Generic Content post type.
A basic structure for single-generic-content.php for the Twenty Fifteen theme is
<?php get_header(); ?> <div id=“container”> <div id=“content” role=“main”> <?php get_template_part(‘loop’, ‘generic-content’); ?> </div> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
By using the template part, creating a loop-generic-content.php file allows for easy customization of The Loop for the Generic Content post type entry.