Index.php is loading before Home.php (4 posts)

  1. leejk_sun
    Posted 5 years ago #

    This normally isn't a problem since I can use is_home() to make index.php display the correct content, but I try my best to adhere to standards, so I created a home.php template to follow the Template Hierarchy.

    The site is using WordPress as its CMS, not just a blogging tool, so the instance is installed to the root of the host; the URL http://www.mysitename.com/ will send you directly to the WordPress instance.

    What happens in my case is that index.php is being called before home.php; is home.php only called first if the WordPress instance is installed to a sub-directory (http://www.mysitename.com/wp/)?

    I do not have a static page set for the site.

    This isn't going to stop development, but I would like to adhere to the Template Hierarchy to future-proof the site against changes to the template structure.

    Any advice would be helpful, so thank you in advance.

  2. Sounds like you are on the right track.

    In your WordPress root, index.php will always get loaded first. It's a web server configuration and that's the normal behavior.

    The home.php is for your theme directory. When you create the home.php file there, it takes care of the is_home() for you.

    See this list for more information.


    See the rest of that article for additional theme info.

  3. leejk_sun
    Posted 5 years ago #

    Thanks for the reply!

    I understand that the server will look for index.php first, but as I understand how WordPress works, the server will find index.php in the root of the instance (which defines() the theme and calls wp-blog-header.php), then draws out all the theme templates from the theme folder.

    Inside that theme folder I have an index.php file (as required) and a home.php file. If I am understanding the template hierarchy correctly, when the index.php file in the root of the instance calls the templates in the theme folder, it should load up what I have in home.php instead of index.php.

  4. leejk_sun
    Posted 5 years ago #

    This question really stems from this paragraph (from http://codex.wordpress.org/Template_Hierarchy#Examples):

    "If a visitor goes to your home page at http://example.com/wp/, WordPress first determines whether it has a static front page. If a static front page has been set, then WordPress loads that page according to the page template hierarchy. If a static front page has not been set, then WordPress looks for a template file called home.php and uses it to generate the requested page. If home.php is missing, WordPress looks for a file called index.php in the active theme's directory, and uses that template to generate the page."

    When they cite this url: "http://example.com/wp/" it makes me inclined to believe that the Template Hierarchy in this case (but hopefully not others) will only work in sub-directory installations of WordPress.

Topic Closed

This topic has been closed to new replies.

About this Topic