Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Theme Development Custom Post Type Templates in WordPress The Portfolio Homepage

Elliott Bernstein
Elliott Bernstein
10,105 Points

The Templates dropdown doesn't appear in Page Attributes area when editing/creating a new Portfolio Piece. Using WP 4.1.

I'm unable to get the Templates dropdown to appear in the Page Attributes area when I'm editing or creating a new Portfolio Piece.

I've read online that this dropdown won't appear in some newer versions of WP. Is that why I can't get it to display?

I've researched a solution, which is adding code to functions.php that checks post_type and sets a template. So I have gotten it to apply the template to the first Portfolio Piece. But it'd be much nicer if I didn't have to add the code each time I create a custom post type.

4 Answers

Elliott Bernstein
Elliott Bernstein
10,105 Points

As I worked through the lesson, I realized this was based on my own misunderstanding.

I believed we were creating new custom posts of the portfolio piece type. In fact, the lesson was asking us to create a new PAGE called Portfolio on which all portfolio pieces would be displayed.

Since it's a page we're creating, and not a custom post type, of course the template field shows up, and the portfolio page template is listed among them.

Andrew Losik
Andrew Losik
3,808 Points

Just re-read your answer... thanks, this was helpful. I made the same mistake.

Elliott Bernstein
Elliott Bernstein
10,105 Points

Since the lesson is focused on teaching us how to build a custom template, we're not actually writing code to register the custom post type. We're using two plug-ins, "Custom Fields" and "CPT UI".

I'm sure if I dig around in the CPT UI files, I can find the code though...

Andrew Losik
Andrew Losik
3,808 Points

I'm having the same issue. Worked around it (e.g. got the page template to apply to the portfolio pieces) by saving it as single-portfolio.php rather than page-portfolio, but as above, it would be preferable to have the option to choose the template under the attributes menu (Also, like Elliott, I can see the template on pages and posts, so I know I've at least partially set it up properly)... Did this ever get resolved?

Since you can can see the templates for posts and pages then you have set you templates correctly.

The most likely reason for this is that your post type doesn't support the page-attributes.

Usually, when you register your custom post type you define what your post type can support and by default this is just title and editor.

See the supports option here: https://codex.wordpress.org/Function_Reference/register_post_type#Arguments

Since i don't know the plugin you are discussing i'm not sure where you would set this, but this will hopefully set you on the right track.

You need to have templates available in your theme for this to work.

For example, to denote a template you need to have this as the header in the file.

/*
 * Template Name: My Template
 */

Without that header Wordpress doesn't know which of your theme's files can be used as templates.

From Page Templates

Template List Will Show Only If:

  • There is at least one custom page template file in your active Theme's folder. If you change your Theme, the page templates in your previously activated Theme will not display.
  • You are viewing a screen for editing a Page: page templates are not a default option for posts or custom post types.
Elliott Bernstein
Elliott Bernstein
10,105 Points

Thanks, Liam. I know this template is functional since it already appears in the dropdown list for other pages.

For example, I set my "home" page to the portfolio template just to check it, and it loaded while displaying the portfolio template.

My question is about how to get the list of templates to display in the Page Attributes section when I am creating a new Portfolio Piece. Currently, when I create a new Portfolio Piece (or edit an existing one), the templates menu doesn't display in the Page Attributes section.

Maybe of some interest as well, the Parent dropdown does not display either, there is only an "order" text field with the number 0 in it.

But back to the second point in that list you posted. If we are creating a custom post type, and it explicitly states that templates are for Pages only (and NOT custom post types), then how has the lesson's teacher gotten it to display.

Can you post the code used to register this custom post type?