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 The WordPress Template Hierarchy Page and Post Templates in WordPress Post Formats

Unclear about the function of content.php content-page.php and content-none.php

From what I understand, single.php and/or single-post.php will call via get_template_part() the content-postTypeHere.php files.
I'm assuming this is b/c each content-postTypeHere.php file is coded to accommodate the different post contents.
Zac mentioned that content.php, content-page.php and content-none.php are utilized when no post type is selected, but what is the difference b/w them?
How is content-page.php different than page.php?

2 Answers

Hi Nijad

Each of those content files are aimed at a specific type of wordpress page so you can provide a different layout if necessary.

You could get by with only the one template (content.php). That's usually less than ideal.

For example I have my list of blog posts. I want that to have a title, excerpt and link to read the full article. I don't want the excerpt and link to show up in the full article so I will change that in content-single.php and instead have the title and the full content.

It also helps keep your code organised and easier to read. Instead of having conditional statements littered throughout the one template.

To answer the difference between content-page.php and page.php:

content-page.php is used to contain the output content generally. page.php will contain any general layout things and extras. The benefit to content-page.php is it could be used in single.php but with different markup to that of page.php.

Hopefully this helps. Let me know if I can explain it better.

Thanks Steve!!
Your 2 responses cleared it all up for me!

Thanks for the reply Steve!
Cleared up a lot but I'm still confused about a few things:
1) so the content-postTypeHere.php files are not specific to posts pages? i.e. for displaying posts pages w/ different layouts/properties? they can also be used to output/format static pages?
2) still don't understand the relationship b/c content.php and page.php and she each is used...sorry for being thick!

It's essentially someone's choice to code their wordpress website using this method. So don't feel bad for not understanding it.

  1. They're not specific to the page. It's just a kind of best practice following on from wordpress hierarchy. It's always handy to refer to the template hierarchy to see what pages wordpress will follow by file name.

  2. The idea is to stop repetition of similar Wordpress loops generally. content.php could have a generic loop that would be suited to archive.php, category.php and home.php. If you had the contents of content.php copied and pasted into each of those pages you would have to update it 3 times. The aim is to cut that out, though sometimes you may need a slightly different loop for a page so you make content-page.php. There really is no relationship between content.php and page.php, it's a naming choice. I could use loop.php instead of content.php.

Hopefully this helps.