0

I am currently developing a theme in wordpress for learning purposes.

To set out to you my page hierarchy I have the following:

  • index.php: fallback for all website pages
  • home.php: blog page
  • front-page.php: static front page
  • page.php: default fallback for individual pages
  • single.php: single post page
  • header.php and footer.php

I wanted to know what difference between an index.php and a page.php should display?

On my index.php, I have only the header(); and footer(); functions.
On my page.php, I have my main content div with the standard loop that outputs my page posts from wordpress, with the exclusion of the header and footer functions

Would my index and page files be correct in outputting the content like this?

Thanks.

1

Would my index and page files be correct in outputting the content like this?

No. If you attempt to search, or browse posts by tag or category, then you won't see any posts because your index.php file doesn't loop through any posts, according to your description.

All templates in the template hierarchy should use the standard loop because WordPress will query the correct posts and then use the appropriate template to display them. As you can see from the template hierarchy diagram, there are several post archives that will use your theme's index.php template, so it's important for that template to include the loop. The only exception is the 404.php template, which will not need to display any posts (since none have been found).

Since you have single.php and page.php templates in your theme, your index.php file only needs to be optimised for displaying lists of multiple posts, for things like date and category archives, and search results.

| improve this answer | |
  • Ahh okay, Thanks for your clarification Jacob! ;) – Krys Oct 8 at 7:54

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.