最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

templates - Differentiation between index.php and page.php

programmeradmin2浏览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.

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.

Share Improve this question asked Oct 8, 2020 at 6:06 KrysKrys 1353 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论