Post templates are configured similarly to page templates in that they have a particular style of PHP comment at the top of them. Each post template must contain the following, or similar, at the top:


First note: Page templates use “Template Name:“, whereas post templates use “Template Name Posts:“.

Second note: You must have the custom post template files in your theme in the same directory/folder as your index.php template file, not in a sub-directory/sub-folder.

DEVELOPERS

If you want to implement the custom post templates on a custom post type, you can use the cpt_post_types filter, here’s an example below of adding the custom post template selector and metabox to the “Movie” and “Actor” custom post types. This code can be added to a plugin or to the functions.php file in your theme.

/**
* Hooks the WP cpt_post_types filter
*
* @param array $post_types An array of post type names that the templates be used by
* @return array The array of post type names that the templates be used by
**/
function my_cpt_post_types( $post_types ) {
$post_types[] = ‘movie’;
$post_types[] = ‘actor’;
return $post_types;
}
add_filter( ‘cpt_post_types’, ‘my_cpt_post_types’ );