Build a Template for a Custom Post Type in WordPress
By default, custom post types utilize the single.php template in your theme — 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.
First, you build a simple custom post; in this example, it is called "Generic Content." After you add that, the Generic Content menu in 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 adds 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 from the preceding section). 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 Ten 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.