• Categories
    • Coding
    • Design
    • Inspiration
    • News
    • WP Plugins
    • WP Themes
  • Start Here
    • How to Start a Blog
    • Make A Website
    • WordPress Hosting
  • Freebies
  • Deals
    • WPEngine Coupon
    • WPX Coupon
    • Elegant Themes Coupon
    • View All Deals
  • Glossary
How To Create A WordPress Theme From A HTML Template Part 1 – Introduction

By Ragnar February 2, 2017

How To Create A WordPress Theme From A HTML Template Part 1 – Introduction

This is the first part of a longer tutorial on how to create a WordPress Theme from a HTML Template. Just by following along with the steps in the next few parts, you will learn how to turn a HTML template into a fully functional WordPress theme.

But if you don’t know what you are working with, and all you do is copying and pasting bits of code you can’t differentiate, it is easy to make mistakes and exceedingly difficult to fix them by yourself.

For that reason, in this part we will talk about key parts of WordPress as a whole, and introduce the different working parts of a WordPress Theme.

Before you even get started reading through this introduction, ideally you would be familiar with HTML/CSS and at least have some basic PHP understanding.

The WordPress Loop

Let’s start out with the thing that powers all of WordPress: The WordPress loop, also known as just “The Loop”, is a block of PHP code used to display posts or pages in WordPress.

Using PHP’s alternative syntax, the loop looks like this:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts were found.' ); ?></p>
<?php endif; ?>

This the normal way of writing the loop these days. But when using the more old fashioned way of coding it out, the loop looks like this:


 <?php
 if ( have_posts() ) {
 while ( have_posts() ) {
 the_post();
 } // end while
 } // end if
 else {
 _e( 'Sorry, no posts were found.' );
 }
 ?>
 

The loops calls on pre-written PHP functions within WordPress that do certain things.

Have posts pings the relevant database, and asks it if there is any content available. Because it uses a PHP if clause, if there is content available, it moves on to the next step, whereas if there is no content available nothing happens, it plays through the else code instead. In this case, it simply echoes out the text “Sorry, no posts were found.”

Using a while clause in PHP creates a loop that keeps doing something as long as the condition you specified is true. In this case, the condition we have specified is “have_posts”, meaning that as long as there are posts in the database, it will keep looping through the code within the clause.

the_post, calls another PHP function within WordPress, that simply echoes out the relevant post from the database. Because the_post is inside the while loop, it will keep echoing out posts until no more posts are found for the query made by the have_posts function.

You can read more about the loop here, and see more complicated examples of what is possible to do with it.

The Core Files Of A WordPress Theme

Next let’s take a look at the absolutely required core files of standalone WordPress Theme. When you make a child theme, you only need style.css and functions.php. When you make a completely new theme, in theory you just need one more file, indexx.php.

Index.php – Complete With The Loop

This is the default fallback page for all possible pages a person might visit on your WordPress site. If there are no page.php or post.php files available, this is the template it will use to serve up the content on a url that is visited.

Most themes however, make ample use of many templates within in the WordPress template hieararchy.

Functions.php File

This is where you will pull in necessary outside scripts, and register functionality that exists in your WordPress theme. For example, if you want to work with the WordPress Customizer, you need to do that from within the functions.php file, as well as your actual template files.

Later in the series, you will see exactly how to add “header image”, and other customizable aspects to your WordPress theme, and make full use of the WP Customizer as a developer.

Style.css

WordPress templates like most modern websites rely heavily on CSS to control the and result of their look. And in this file is where the CSS in your theme will be. (If you don’t know what CSS is, you should probably at least go through the HTML/CSS course on Code Academy before continuing with this guide.)

Even if you prefer to use SASS, you will still need to compile it into a regular style.css file before you can work.

Basic Site Architechture

Rather than building each different page template from scratch, WordPress themes typically work with different building block templates, that you piece together and then build on top of. The bare minimum of these is the header.php, sidebar.php, and footer.php files. The thinking behind this is that these parts require fairly substantial bits of code, and are likely to be included in almost every page template. You also get very cleanly separated code, so that it is easier to edit down the road.

All you need to do to call in a template is use the “get_” function. If you want to call in the sidebar.php file in a certain place in your page template, all you need to do is type this snippet:

<?php get_sidebar; ?>

You can also create multiple sidebar, header or footer templates with different names. But make sure to follow this naming convention “header-ADDEDWORD.php”. For example, you might create a “header-fullwidth.php” to show a different header on full width pages. Calling this file would look like this:

<?php get_header('fullwidth'); ?>

But many modern themes go a lot deeper than this, and even have different template-parts, for their different templates for different parts of the page. The newest official WordPress theme, Twenty Seveteen, for example, does this.

Template Parts Twenty Seventeen

This means that instead of calling the WordPress functions for sidebar and content in the actual template files, they are called in the different part files. Then you simply call those part files from your template files. Then finally call the templates into your different page templates.

You can read more about site architecture in WordPress here.

The Template Hierarchy

The template hierarchy refers to the way that WordPress decides which template to use to serve content on a certain permalink. Basically there are certain template files that WordPress prioritizes differently in different situations. Usually this is determined by which permalink the visitor is on and what content is supposed to be displayed.

As an example, to show the way the template hierarchy works:  If a visitor goes to the permalink of a single post, WP will first look for the single-post.php file. That’s the template file designated to showing standard single posts, so that has first priority.

If there is no single-post.php file, WordPress will look for a single.php file. That is the file used for displaying any kind of single post, custom or standard.

If there is no single.php file, it will look for a singular.php file. That is the file used for displaying any kind of single post or page.

Finally if there is no singular.php file, WP will default to the index.php file, which is the last resort used for displaying all content.

The process is the same no matter what post or page the visitor visits. For example, if a user visits the front page, it looks for a front page.php file. Failing that, if it is a single page displayed, it pulls in the relevant page template file. If posts are displayed it looks for the home.php file. Finally, if there is no home.php file, WP defaults to index.php again. I’m sure you’re starting to understand exactly why an index.php file is absolutely necessary.

You can see a full visual representation for how WP does this, over at wphierarchy.com.

Let’s Get Right Into It

Now that you are familiar with most of the basic working parts of a WordPress theme, let’s jump right in. Starting in the next part, we will create a very basic WordPress theme that uses all of the CSS styles of the original HTML template.

Related Posts

Reader Interactions

Droppin' design bombs every week!  5,751 subscriber so far!

You have successfully joined our subscriber list.

3 Comments

  1. Coralie
    8 years ago

    Nice article, very clear.
    I can’t wait for the next parts.

    Reply
  2. andy brookes
    8 years ago

    Very readable unlike official WP source & great intro to WordPress themes couple – of typos including :
    ….theory you just need one more file, indexx.php. [index.php]

    …………….it looks for a front page.php file. [front-page.php]
    I had a go at wp theme using bootstrap https://github.com/captain-sensible/wp1 example use: bimschoolgh.com biggest problem is understanding how to override say underscore theme with bootstrap. if you look at style.css of underscore its difficult to see how it styles ten there is body_class() which adds style class to body element.

    Reply
  3. Grace
    8 years ago

    I love how clear and straightforward this intro is structured! I’m a bit fuzzy on some parts of WordPress even though I know that it’s not as insanely complex as it seems.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

Primary Sidebar

Subscribe

Join our 5000+ subscribers & get access to freebies, new tools, and much more!

You have successfully joined our subscriber list.

Useful Guides

What is WordPress?
How To Make A Website – Step by Step Beginner’s Guide
9 Best WordPress Hosting Compared (December 2024)
8 Best Backup WordPress Plugins Compared – 2023
14 Ways to Secure Your WordPress Site – Step by Step
Top 9 Email List Building Plugins for WordPress Compared (2023)
Build Your Tribe: 6 Top WordPress Membership Plugins Compared for 2024
11 Best Website Builders of 2022: Wix, Squarespace, Weebly, & More
8 Best WordPress Contact Form Plugins for 2024
How to Use Facebook Debugger and Open Graph to Fix Posting Issues
Top 10 Free Website Speed Test Tools for 2024
5 Top WordPress Landing Page Plugins Compared (2024)
5 Best WordPress Learning Management Systems (LMS) Plugins Compared – 2022
20 Best Google Fonts & How To Use Them
7 of the Best FTP Clients for Mac & Windows
11 Dropbox Alternatives to Securely Store Your Files in the Cloud
25 of the Useful and Best Brackets Extensions
What is Loremp Ispum? 18 Plain & Hysterical Lorem Ipsum Generators for 2024
How to Clear Browser Cache (Google Chrome, Firefox, Safari, Opera, Microsoft Edge, & Internet Explorer)
6 Best Managed WordPress Hosting Options for 2024

Latest Deals

  • Elegant Themes: 20% OFF on the best drag & drop theme & plugin
  • WPEngine Coupon: Get 20% off the best Managed WP Hosting
  • WPX Coupon: Get up to 50% off on one of the best hosting providers
  • Inmotion Coupon: 47% off + Free Domain on Inmotion hostnig
  • View More Deals  

Categories

  • Adobe Photoshop15
  • Coding19
  • Design36
  • Fonts28
  • Freebies3
  • Inspiration52
  • News6
  • Resources58
  • Showcase14
  • Tutorials6
  • WordPress Plugins29
  • WordPress Themes27
  • WordPress Tutorials27
  • WP Hosting13

DesignBombs content is free, which means that if you click on some of our referral links, we may earn a small commission. Learn more!

Home About WordPress Hosting FTC Disclosure Privacy Policy Contact

© 2008-2025 All Rights Reserved.