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 How WordPress Templates Work Common WordPress Template Code

how does wordpess know what page it's on

I see the loop and understand that. Does wordpress interpret the url to set up what is on the page?

5 Answers

I think what you are looking for is the template hierarchy, this is the template structure used to figure out what it is you are tying to display and then run the most appropriate template.

For example, if you have a custom post type called books, you can create a specific template to handle single book posts rather than using the default index.php.

This would be a good read - WordPress Template Hierarchy

I have always found the infographic on this page really helpful and even have it as bookmark to this day. WordPress Template Hierarchy Infographic.

Hope this is what you are looking for.

Craig

Hi Marie,

The simple answer to that is - a mySQL Database.

WordPress takes the fields you fill in within the admin area of a post or page and stores that data in the database ready to be retrieved on request. When it is stored in the database it has an ID is given to that post. The post ID is the source of all things great!

To have a dive into things, get a local install set up and navigate your way into phpMyAdmin, take a look through the database structure, this is what WordPress queries and retrieves the content from that you created in the admin area. You really want to have a look at the wp_posts table, this will give you a good insight into have things get stored and then how they can be queried and retrieved.

I hope this is more in line with what you are looking for.

Craig

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

WordPress looks for something called a permalink which is a link that is either generated by WordPress itself or you can define a custom one before you publish or edit a page. Then it pulls in the content you create in the WSYISYG editor. So it's a permalink that differentiates pages to WordPress. :-)

Sorry. I guess I'm not being clear with my question.

Yup. I understand the wordpress hierarchy so that's not my question. Yup. I understand that a permalink differentiates the pages.

Getting closer with the statement here: "Then it pulls in the content you create in the WSYISYG editor."

What I'm asking is what does wordpress DO with the permalink - HOW does it know what "content" to pull into the page. ie; I can see a permalink here: http://localhost/treehouse-theme/?page_id=6 This is a post or page with an id of 6. How does it "translate" the permalink into knowing what content to put on the page that is called? What is running inside WP that goes and finds the content associated with page_id of 6?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

I'm afraid the answer to that is way beyond my expertise. Someone else may be able to help you but just know that the team at WordPress use PHP to build the framework and allow us to create content. If you want to look further at the code you can download your installation to localhost (if you haven't done so already and look all the individual files in the folders wp_content, wp_admin and wp_includes.

Good luck.