1

I have a custom post type called location. I would like to be able to use 2 different templates for this custom post type and select it via the page attributes box. I have a template set up and can select it when I'm editing a Page, but not when I am editing a custom post type. I can't find any information on how to enable this. I want to enable the dropdown select for all the custom post types, not just one.

  • 1
    template exists only for post type page. for custom post type you have to do everything by yourself : creating the metabox in the backoffice, saving the value et generating the public page with the selected template – mmm Jul 13 '16 at 17:21
  • Thanks, that's given me an idea. I can pull in a template part depending on the category selected. – MrFox Jul 14 '16 at 8:24
3

Since WordPress version 4.7 Post-Type-Templates are enabled in the WordPress core.

That means that you can create multiple templates for the single post-type view as for pages.

For this you just need to edit the single post/type template, and add something like this to the top of the file:

/*
Template Name: Custom Type Template 
Template Post Type: post, product, custom-type 
*/

On the line Template Post Type you just add your custom post type slug.
So this template will be available on the post, product and custom-type post type.

I already answered this here.
Read more about post-type-templates of WP 4.7 here.

0

Ok as mmm has pointed out that I can't do the dropdown select of templates on custom post types I have put this code in my single-cpt.php

global $post; 
if ( ( $post->post_type == 'location' ) && has_term( 'news', 'highlights' ) ) { 
include('templates/template_feature_highlight_layout.php'); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.