Convert HTML to WordPress

Posted: May 16, 2010 in CSS, HTML, PHP, Wordpress
Tags: , ,

When I first decided to convert a static HTML design to WordPress I did some searching for a tutorial to help me get started with the basics. Surprisingly, I didn’t find anything that was very complete or easy to follow. For that reason I decided to write a very basic tutorial on how to convert a static XHTML/CSS template into a WordPress Theme. If you are an absolute beginner at developing WordPress themes then this should help you get started. This tutorial assumes you already have a basic understanding of HTML and CSS. It also assumes you have already built a website in XHTML and CSS and have it ready for conversion. Don’t worry about XHTML vs. HTML, it doesn’t matter for this tutorial.

How WordPress Works:

WordPress works in a rather straightforward manner but it may seem confusing if you are completely new to the concept. WordPress relies on PHP to call on different parts of your content from the database management system it stands on. For example, look in your /wp-content/themes/default/ directory and open the header.php file. As you scroll through the code notice the PHP calls, they start with a . Look at line 15 and notice the call for your stylesheet URL:

<link rel="stylesheet" href="" type="text/css" media="screen" />

This line uses PHP to look-up your stylesheet’s location from the database. This basic function of retrieving or calling some kind of data from your database and using PHP to display it in your XHTML is how WordPress works. Throughout this process you will be substituting PHP for different parts of your content and your code. This will make editing easier in the long run, as you will find out. Now that you understand the basics of how WordPress works, lets get started.

First Things First:

The first step is to create a new folder and name it whatever you want your theme to be called. Next, create two new files, style.css and index.php and place them in the folder. Believe it or not, these are the only two files you actually need for a WordPress theme. Now copy and paste the code from your original CSS file into the style.css file you just created. At the top add the following code:

/*
Theme Name: Replace with your Theme's name.
Theme URI: Your Theme's URI
Description: A brief description.
Version: 1.0
Author: You
Author URI: Your website address.
*/

These comments simply help WordPress properly identify the theme. Your stylesheet is now ready to go.

Chop It Up:

Now let’s start chopping up your XHTML. Remember how we talked about WordPress using PHP to call data from your database? Well WordPress can also use PHP to call different files from within your template folder. Imagine your current XHTML code chopped up into 4 (or more) different sections. For example, take a look at the layout and corresponding XHTML of this page. The header comes first, followed by the sidebar, then the content, and finally the footer. Instead of keeping these 4 parts of the XHTML together in one file, you are going to put each of them in their own separate file. Then call on them one by one using PHP.

So go ahead and sort through your XHTML code and place some markers in the 4 places where you plan on cutting the code into 4 separate sections.

Note: These next steps assume you have your page set up left to right: header, content, sidebar, footer. If your page is ordered differently you will have to switch a couple of these steps around, but I am sure you can figure that out.

Now create 3 new files (header.php, sidebar.php, footer.php) and place them in your theme directory. Next take a look at the header.php file from the default theme we looked at earlier. Notice all the PHP that is used in between the tags. You will want to keep most of this code. First, remove lines 18 – 29 and copy the rest of the section into your new header.php file. Now open up your original XHTML file and copy the code you marked off for your header (1st section) into your new header.php file (underneath the section). Save and close.

Now open up your new index.php file. Copy the second part of your original XHTML code, the content (2nd section) into your new index.php file. Save and close.

Getting the hang of it?

Next open up your new sidebar.php file, copy the sidebar (3rd section) of your original code into the sidebar.php file. Finally, copy the original footer (4th section) of code into your new footer.php file.

Put It Back Together:

Your original code should now be chopped up into 4 different files (header.php, index.php, sidebar.php, footer.php). Let’s put it back together using a few lines of PHP. Open up your index.php file, it should contain the XHTML from the content (2nd section) of your original code. Add this line at the very top of the file:

Now go to the absolute bottom of your index.php file and add these two lines:

These 3 simple lines of PHP are telling WordPress to fetch and display your header.php, sidebar.php, and footer.php files within your index.php file. Your code is now officially put back together. Now, if you want to edit your sidebar you can just edit your sidebar.php file, instead of sorting through your index.php to find it. The same goes for your header.php and your footer.php

The Loop:

Your index.php is almost finished. The final step is to insert the actual content into the code. Luckily, WordPress uses PHP for this as well. The Loop is the PHP function WordPress uses to call and display your posts from the database they are saved in. Look in your /wp-content/themes/default/ directory and open the file index.php file. Copy everything in between and to your clipboard. Now paste it into your new theme’s index.php file inside of whichever div you are using to hold your content. You just inserted a basic version of the loop into your code. WordPress will use the loop to display your posts and comments on your website.

The End:

Now upload your theme folder to /wp-content/themes/. Then log into WordPress and activate your theme. Wasn’t that easy?

This tutorial covered the basics for converting your theme to WordPress. To further customize and enhance your theme start looking at the WordPress Codex, specifically Template Tags and Template Files. You can use template tags in your sidebar, in your header, or your footer to call menus, categories, posts, etc. As you learn more about template tags and template files you will discover the endless possibilities for customizing your new WordPress blog.

Advertisements
Comments
  1. James G. says:

    So basically you are saying that I dont have to go thru every bit of my html and replace my html tags with php tags? Also, I make some pretty awesome html/css templates and themes, how much would you charge me to convert them properly?

  2. Gregory says:

    Good info, still waiting for your next posts…

  3. codehunterbd says:

    @Gregory,Check my recent posts of WordPress theme tutorials.

  4. Web Tutorial says:

    Nice template, I like it! You are wordpress master.

  5. Web Tutorial says:

    Sorry, again. Can you tell me where you got the template for wordpress? Thanks.

  6. babloo aro says:

    i am learning wordpress in last two month but no gain how easly learn please advice

  7. Smitd says:

    Help what if you have multiple 1: css style sheets
    2:multiple jquery plugins
    3:multiple sets of navigation menues?
    How is this handled?
    Thanks

    • codehunterbd says:

      For multiple jQuery plugin the codes are below :

      var jQuery_1_1_3 = $.noConflict(true);

      var jQuery_1_3_2 = $.noConflict(true);

      Then, instead of $(‘#selector’).function();, you’d do

      jQuery_1_3_2(‘#selector’).function(); or jQuery_1_1_3(‘#selector’).function();

      and for css is basic rules of css

      Thanks
      Khairul Alam

  8. 愛上寂寞 says:

    I came across to your website when i trying to search “convert html to wordpress tutorial”. Saw your comment that you said you will make a video and upload to this website, is it true?

    Where is the video? I’m waiting for it and need it badly. I successfully convert my html template to wordpress but can’t work normally…like my blog post doesn’t show nicely…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s