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 trialMorg Clemmons
Courses Plus Student 403 PointsSo what is in index.php?
If no template (that fits the page type) is found it goes to index.php So what is in index.php? How did it get there? Maybe via the way the template is designed? Thanks
2 Answers
Shawn Gregory
Courses Plus Student 40,672 PointsHello,
I'm guessing you are talking about WordPress by how you worded your post. In WordPress, index.php (when talking about templates) is an end-all catch-all file that is required for a template to work. This file is one of the requirements that WordPress looks for to make sure that a template isn't broken. Since you can have many differently-named template files for pages, posts, statics, etc, there is a chance that a page type may not have the template file that WordPress needs in order to compile that specific page. Remember the template hierarchy Zac explained? Index.php will have a basic generic default template structure that WordPress will use in case a template structure that could have been built for a certain page isn't there. Remember, all a template is is how the page is structured and looks so there could be many different types of templates for one type of page. This is just how WordPress gracefully catches missing template page types. So to answer you question (if it hasn't already), the index.php file is there as WordPress's last resort to render a template for a page, is required for a template to work, and renders a default simple generic template that can be used by every singe page created by WordPress. Hope this helps.
Cheers!
Morg Clemmons
Courses Plus Student 403 PointsThat was extremely helpful Thanks!