Let’s say you are thinking about all the files that a typical WordPress theme contains and wondering what of that is actually necessary for your site to work. If you are in need of a very simple theme, say to display an images or few, you could quickly make it from scratch. Here is the start.
The minimum requirement for a WordPress theme to work are index.php and style.css files.
The style.css file sets the name of your theme which will be displayed in the dashboard. The format is this:
/* Theme Name: My New Minimal Theme */
That’s it, we only enter the theme’s name. Please note the commenting, it is required. Below this part is where your style will be added.
The minimum of content for the index.php file is a loop in it’s simplest form:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); the_content(); endwhile; endif; ?>
That’s it. You will be able to show the content of whatever page or post(s) are set to display as homepage.
Now we can easily build from there. To add a post title, the code should look like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); the_content(); endwhile; endif; ?>
And so on… In the next post we’ll be adding navigation. And let’s see just how many lines of code it takes to make a simple, functional and responsive theme.