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

Shane Cutts
Shane Cutts
15,107 Points

CPT template and single-$posttype.php

If a custom post type will automatically use single-$posttype.php to display content, why do we create a page template for 'Portfolio' (for example)? Do these function the same? Differently? Do they work best together?

1 Answer

single-$posttype.php is the template file that displays the details page of your post. The "Portfolio" template is a overview of posts (in this case portfolio pieces). Take a news page for example which displays a bunch of article teasers. You click on a article teaser and see the whole article page -> this is the single template.

So usually you have a custom page template file that loops through your custom post. And a single template file that displays your custom post. Hope this makes it more understandable.