WordPress / Learn

WordPress.org Learn - The canonical source for the code and content behind https://learn.WordPress.org
266 stars 94 forks source link

Template hierarchy #2272

Closed cynthianorman closed 2 months ago

cynthianorman commented 7 months ago

Details

Learning Objectives

Related Resources and Other Notes

Automation Code

github-actions[bot] commented 6 months ago

Lesson Development Checklist

cynthianorman commented 4 months ago

This Intermediate Theme Developer Learning Pathway Lesson is ready to be reviewed. Please follow the steps listed under Guidelines for reviewing content. Thank you for your contribution! ✨

https://youtu.be/VAgtcFktQZE (unlisted)

ironnysh commented 4 months ago

Tutorial/Lessons Review Checklist

@cynthianorman, the lesson does a great job explaining the topic.

However, I'm a bit confused about the items mentioned in the Learning Objectives:

Explain how WordPress uses the query string Briefly explain the template hierarchy diagram Describe the template hierarchy for a given page being queried

Can totally be my lack of understanding, but I couldn't figure out how the first part (query string/permalink) relates to the template hierarchy :-)

cynthianorman commented 4 months ago

@ironnysh if you think about how the data is stored within the wp_posts table. For a page we'll find post_type=page The id of the page corresponds with the given post type so WordPress knows to look for page templates and follows left to right to see if the file exists. Does this help? Here's more info https://developer.wordpress.org/themes/basics/template-hierarchy/#the-template-file-hierarchy

ironnysh commented 4 months ago

Thanks for the explanation and the link, @cynthianorman. Alright, this makes much more sense--I guess the part that threw me off was the focus on permalinks

cynthianorman commented 4 months ago

@ironnysh I was thinking after the Sample Page loads I could go into the database table and show how WordPress now knows what template to look for because of the post_type value.

Would my example tie things together better? I want this concept to be solidified in people's minds.

Thanks for your help!

ironnysh commented 4 months ago

go into the database table and show how WordPress now knows what template to look for because of the post_type value

Sounds perfect!

Thanks for being attentive :-)

jonathanbossenger commented 2 months ago

Youtube URL: https://youtu.be/sDWvuYzeW4E

cynthianorman commented 2 months ago

@jonathanbossenger

YouTube chapters:

(0:07) Learning objectives (0:23) Explain how WordPress uses the query string (2:46) Briefly explain the template hierarchy diagram (3:23) Describe the template hierarchy for a given page being queried (4:07) Next steps

cynthianorman commented 2 months ago

//publish