1

I recently learned about the differences between home.php, front-page.php, and index.php. I rightly created a front-page.php to handle the Landing page, a home.php to handle the blog (posts list) and an index.php to manage the other paths.

So far, the front-page.php is handling the landing page and I expect the home.php to handle the /blog path. But when I go to the /blog path, it uses the 404.php template and tells me "page not found".

I learned I could make the /blog path work by creating a static page called blog and assign the post page to show the blog page (settings >> reading), but I think this is too crude and do users need to do this themselves?

So I'm confused at the moment and would need your help.

How can I make my /blog path work?

Thanks for your answer in advance.

0

That's exactly what you need to do. The home.php file is used if you're using the main page of your site to display posts or if you have created a separate static page - your Blog page in this case. Perhaps you find it crude but it's perfectly normal to do this.

If you don't change the reading settings, the main page of your site will show your list of posts (more of a traditional blog).

Have a look at the Template Hierarchy documentation as this goes into more detail - specifically the Home Page display.

| improve this answer | |
  • Thanks for your answer Alex. Just to be clear, if I was developing a Wordpress theme, I would normally make the home.php template automatically answer the /blog path and the front-page.php answer the root of the site. But for the user to make this work, they would need to create a blog static page? – Vick_onrails Apr 25 '19 at 9:06
  • That is basically correct. The other option would be to implement a check for your theme being activated, and at that point you can check for an existing blog page, otherwise create a new page. You can then use update_option to set page_for_posts / page_on_front. I'd just leave it to let the user create the page as it's a common thing to do. Good luck with your new theme and welcome to the site. – Alexander Holsgrove Apr 25 '19 at 9:18
  • Thank you very much Alex. For some reason, I can't upvote this answer. – Vick_onrails Apr 25 '19 at 9:25
  • You should be able to accept my answer, but up/down voting on the site needs you to have a bit more reputation (post and answer more questions). – Alexander Holsgrove Apr 25 '19 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.