Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm making my first custom theme using custom post types and I've encountered one problem. I'd like to make some templates like you can make for Pages (i.e. page-fullwidth.php page-noslider.php etc.) I know if you want to make template for custom post type you just make for example single-cookingrecipes.php but I'd like to make single-cookingrecipes-fullwidth.php and some more.

I have created 2 such files and added

<?php
/*
Template Name: Art
*/
 ?>

and still no luck :(

share|improve this question

2 Answers 2

Suppose you make a new page call art.php

    <?php
/*
Template Name: Art
*/
 ?>

Next step you should do is to Go to your admin dashboard. Then follow the simple steps.

  1. Go to Pages
  2. At the right hand side there is "Page Attributes" Template. By default it has "Default Template". Click it.
  3. Select Art.

That's it.

share|improve this answer
    
the attributes meta box for a custom post type doesn't have the templates menu. –  Milo Oct 12 '13 at 17:15
    
Please read the question. Test your suggestion. –  toscho Oct 12 '13 at 17:18

It sounds like you are talking about this page display template:

page-{slug}.php - If the page slug is recent-news, WordPress will look to use page-recent-news.php

And you want single-{cpt-slug}-{slug}.php.

If so, I believe you can approximate that page template handling with the following:

function cpt_slug_template_wpse_117630($template) {
  global $post;

  $templ = locate_template('single-'.$post->post_type.'-'.$post->post_name.'.php');
  if (
    'book' == $post->post_type 
    && 'poem' == $post->post_name
    &&  !empty($templ)) {
      $template = get_stylesheet_directory().'/single-'.$post->post_type.'-'.$post->post_name.'.php';
  }

  return $template;
}
add_filter('single_template','cpt_slug_template_wpse_117630');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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