Quantcast
Channel: Scott Gale
Viewing all articles
Browse latest Browse all 15

How to build a WordPress HTML5 theme

$
0
0

iPhone, iPad, video HTML5 deployment, Webkit, Chrome, Safari, web standards, canvas elements, and disappearing flash support.  These are just a few of the many reasons to explore HTML5 and its capability.  Add WordPress, a very customizable system that allows skinning of the underpinning code in order to achieve the desired result and you get a great basic test case for HTML5.

What follows is quick synopsis of how to setup an HTML5 WordPress skin and some of the benefits this brings:

To start, I setup basic HTML5 markup.  Utilizing new tags.  Here is what the structure looks like:

Using this basic system as a framework, I added microformats to the header and footer for human and machine readable information.  You can view the source and search for “vcard” to see my microformat header.

Next, I started utilizing some of the great things that HTML5 and CSS3 have to offer.  HTML5 has new form field types that work well for the iPad, iPhone, and Webkit.  In other browsers they fall back to be standard text input fields so it’s not a problem to use them in general markup, even for IE6 (everyones favorite).  Here is a breakdown of some of the new HTML5 form fields:
<input type=”search” placeholder=”SEARCH” value=”"/>
The new search input type has a really cool attribute called “placeholder”.  Placeholder is a value that disappears when the form field focuses, a function that we no longer have to emulate with JavaScript on browsers that support this.  The type search also tells the iPhone, iPad, and future dynamic keypads to use a different “enter” key.  Note how the iPad shows “Search” on the keyboard:

<input type=”email”/>
This field type also tells mobile devices to change their keyboard accordingly.  Here is an example of the iPad keyboard with this field type:

<input type=”url”/>
This field type also tells mobile devices to change their keyboard accordingly.  Here is an example of the iPad keyboard with this field type:

Now its time to add the CSS.  Using CSS3 for rounded corners, drop shadows, and gradients, quickly eliminates the need for extra divs, classes, and most importantly, images. I used these styles to do the buttons, the input fields, header and footer styling, and even the background. Here are some of the basic CSS3 styles used:

/* create the body gradient */
body {
	background: -moz-linear-gradient(top, #fff, #ccc);
	background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#ccc));
}
/* do the rounded corners and drop shadow on the header */
header {
	-moz-border-radius-topleft:8px;
	-webkit-border-top-left-radius:8px;
	-moz-border-radius-topright:8px;
	-webkit-border-top-right-radius:8px;
	-moz-box-shadow: 0px 0px 3px rgba(0, 0, 0, 1);
	-webkit-box-shadow: 0px 0px 3px rgba(0, 0, 0, 1);
	box-shadow: 0px 0px 3px rgba(0, 0, 0, 1);
}
/* create the button for form submission and search submission */
form .submit {
	background: -moz-linear-gradient(top, #073842, #000);
	background: -webkit-gradient(linear, center top, center bottom, from(#073842), to(#000));
}

With these styles it’s quick, easy, and image free to do what use to be a much more arduous process for many of us.

Now you’re all done except for IE

Now that the markup is in place and the styles are in place.  We have to make it work for lesser browsers that can’t handle new standards (aka IE).  There seems to be a misconception out there that this is difficult, but it is actually a few simple steps.  For my blog I conceded that there would be some degradation of the look for browsers that don’t support CSS3 so that makes life easier, and of course it may be a luxury not everyone can afford.

IE Step 1: Add support for styling of the HTML5 tags
To do this, all we have to do is include a JS file called html5shiv hosted on googlecode.com.  This in essence does a document.createElement and a few other things to get IE to recognize the HTML5 elements.  We can wrap this in conditional comments because it is only required for IE.

<!--[if lte IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

IE Step 2: IE specific CSS
For any IE specific CSS that you want to do (I added a few different border treatments and color tones to make the site still look ok) add the IE specific CSS file.

So the sum of your checking for IE should look something like this:

<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  <link rel="stylesheet" href="/blog/wp-content/themes/scottgale/style-ie.css" type="text/css" media="screen" />
<![endif]-->

Make sure after you add this to validate your markup with the w3c validator.  It handles HTML5 quite well from my experience.

And now your are done!

I hope this helps everyone to explore this new web standard.  The blogosphere is an easy place to try this out and help perpetuate these ideas.  Please let me know if I need to explore any of these concepts in more detail for people.


Viewing all articles
Browse latest Browse all 15

Trending Articles