Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If I create a home.php file, it seems that WP will use that instead of index.php, so index.php is never used?

What are the differences between these two template files (located in the theme folder)? Do they both behave the same way, the only difference being the priority of home.php?

share|improve this question

3 Answers 3

up vote 15 down vote accepted
  • index.php is universal template, it is what any page (home, archive, single post, etc) will use if no other template is available for it.

  • home.php is a template used for main page (on is_home()) condition.

See Template Hierarchy for detailed scheme of how templates are applied.

share|improve this answer

home.php is what your site will use for whatever page you set be the "Posts Page" under the reading options in wp-admin. If you set a static page to the front page, you would use front-page.php if you wanted it to be styled specially.

share|improve this answer

Be aware that using home.php instead of index.php as the front page will disallow an usual posts-from-all-categories page in your blog. In other words, there's no easy way to get to index.php if you use home.php.

share|improve this answer
    
Can you explain that? Usually, you can get all categories just fine in a home.php. The template will be chosen long after the db query has been made. –  toscho Feb 5 '13 at 16:48
    
Yes, but if you try to implement a site structure like this: 1. Home -> home.php / 2. News -> index.php / 3. Post category 1 -> category.php ... then there's no way to show posts from all categories (the role that index.php fulfills) except by creating a static page, a separate page template for it and getting post via a separate query in this template. If we try to link directly to index.php, it obviously redirects us to the page designed by home.php because it's now set as the front page of the blog. –  certainlyakey Feb 5 '13 at 18:26
    
home.php is the template for the latest blog posts from all categories. –  toscho Feb 5 '13 at 18:39
    
What index.php is for then? –  certainlyakey Feb 5 '13 at 22:48
    
It is a fallback file in case any other file is missing. The only file that is not catched by this fallback is the comments.php. –  toscho Feb 5 '13 at 23:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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