The Content: index.php

Serie WordPress Theme development

Chapter 1. What is a WordPress Theme?
Chapter 2. Creating your own WordPress Theme: Style.css
Chapter 3. The Content: index.php
Chapter 4. The header, the footer and the sidebar

Chapter 3: The Content: index.php

The index.php file is the default template of the site. Usually, the index.php file contains the traditional blog format where the post are displayed in reverse chronological order. For this, it uses The Loop.

<?php  if ( have_posts() ) { 
while ( have_posts() ) {
// Post Content here //
} // end while
} // end if ?>

It is a very traditional programming structure, however the page content could contain multiple different loops from different tags and categories or it could contain no loops at all. It depends on the content you have and how would you like to show it.

WordPress has a built-in decision engine that decides which kind of information is requesting and therefore determines if there is a template file available for that information type. This process is determined by the hierarchy of files. The index.php template is the default so if the WordPress does not determine any specific template to use, index.php is used.


The main template file
This is the most generic template file in a WordPress theme
and one of the two required files for a theme (the other being style.css).
It is used to display a page when nothing more specific matches a query.
E.g., it puts together the home page when no home.php file exists.
@package WordPress
@subpackage Twenty_Seventeen
@since 1.0
@version 1.0

Do you want to carry on with Chapter 4 DRY: the header, the footer and the sidebar?