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 trialKushal Mahajan
Courses Plus Student 425 PointsWhat template file wordpress looks when latest blogs are set to display on homepage as shown in Video vs Quiz quesion?
When latest blogs are set to display on homepage, wordpress still uses front-page.php as a template as shown in video. So it means wordpress looks for front-page.php first and then home.php. Correct me if I am interpreting it wrong !
Then in the quiz the question asks the same I have asked. But the answer to that is home.php and and not front-page.php. How so ? It was clearly shown in video that front-page is in effect. Please clarify!
3 Answers
Dominik Hlusiak
605 PointsI have the same question.
Metka Slamic
841 PointsYap, same question here... plus in the video we saw that that the front page kept functioning as a template (despite blog post on the homepage) until it was renamed. Why?? :(
nico dev
20,364 PointsHi there,
You're not interpreting wrong at all. I had the same issue; after changing from static front page (and blog index page simply in the menu) to displaying "Your latest posts" in the home. The hierarchy seems to be more complicated than it looks at first (at least for me).
I was exploring around and found an explanation and a way, which I'd like to summarize as much as I can, in case you or probably someone else coming later (like me) will have the same issue. In this page of the Codex, WP explains the following, and I quote:
Configuration of front-page.php If it exists, the front-page.php template file is used on the site's front page regardless of whether 'Settings > Reading ->Front page displays' is set to "A static page" or "Your latest posts," the Theme will need to account for both options, so that the site front page will display either a static page or the blog posts index. There are a few methods to do so.
In other words, what this is saying is: no matter which of both you set up, the theme should be prepared for handling the potential change of mind of the administrator. So if it's you who is handling the theme, yes, you could definitely become "all-radical" |o| and remove the front-page.php altogether without mercy, but what about if the user later change the mind again and want the static page again? Most likely you'll need to recreate the front-page file, I think.
An easier, shorter and even less-problem-prone method to do this is by adding a simple conditional statement to the very beginning of the front-page.php file, like so:
<?php if ( 'posts' == get_option( 'show_on_front' ) ) {
include( get_home_template() );
} else {
As shown in the Codex site linked above, the get_home_template
's argument by default is, guess what? Yes, the home.php file. So what that if/else
you're basically telling that Latest Posts is set to be shown on front, then use home.php, else... And then of course all the content of the front-page.php file has to be within that else clause. NOTE: Don't forget to include a last php statement at the very end of the file closing the else clause; that happens to all of us haha!
I'm not saying this is the best solution, but at least it makes it work that way. Hope I'll find out a better way later on though...
Hope that helps someone with the same doubt than me in the future. :)