• Still curious about how WordPress treats an index.php file versus a page.php file. As far as I can tell, in a simple theme there is no page.php file so the loop is in index.php and runs every page on the site.

    In a more advanced theme there is an index.php file and a page.php file. From experimenting it appears that:

    – index.php is needed to make the Theme appear in the Dashboard
    – the content on this page is what you will see if you click on the Theme title in the Dashboard & in preview
    – otherwise pages.php displays content on the website

    Is this correct? If so, it seems redundant to have a separate page.php file.

    Thanks
    Charles

Viewing 2 replies - 1 through 2 (of 2 total)
  • Review Stepping Into Templates and the template hierarchy.

    It’s not redundant. Consider the extremely common scenario where you want a WordPress Page to display differently than the homepage. In this case, the template system automatically looks to page.php. If there is no page.php, it falls back on index.php, which is much more desirable than simply having the website break if it can’t find page.php.

    Thread Starter charles_i

    (@charles_i)

    OK thanks. So if index.php is the only page it will display every page, but if there is a page.php for all other pages, index.php will display the home page – like a regular (non-blog) website. So, is the page specified in Blog address (URL) (in Settings) what determines what will appear in index.php? You couldn’t just determine it with just the name “home” in Pages.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How does index.php differ from pages.php’ is closed to new replies.