phpwordpresswordpress-theming

Wordpress: index.php vs home.php?


Im reading this tutorial Wordpress theming about converting an html site to WP, and it says

WordPress has a hierarchy of templates. None of them are called index (that name is reserved) so we need to rename our index file to something else.

So as per tutorial I renamed index.html to home.php. But when I go to themes it says that the theme is broken as it is missing a template and it shows as a valid theme only when I rename home.php to index.php.

Should I use index.php or keep home.php and it will recognize it after I have other pages like header.php etc?

ps. Tutorial is outdated?


Solution

  • from the codex:

    At the very minimum, a WordPress Theme consists of two files:
    style.css
    index.php

    you need to keep the index.php file. home.php is also uses by wordpress template already as an option for front page as the website home page instead of default blog page - index.php.

    home.php
    The home page template, which is the front page by default. If you use a static front page this is the template for the page with the latest posts.

    if you want to create a new template for home, you can for example create a new php file for new custom template and put the "template name" in the start of the file:

    <?php
    /*
    Template Name: my template
    */
    

    then set the page called 'home' to your new template from the admin panel.