7 July 2009

Author

Jan Vantomme

Categories

Web Development
Tutorial

HTML 5 and WordPress - The <time> Element

I’ve been working on the HTML 5 WordPress theme for La Vie En Ville today. The website is very beta at this time (read: it will only work properly in modern browsers as Safari 4 and Firefox 3.5). In this short tutorial I’m going to show you how to implement the <time> element for blog posts and comments.

Blog Posts

Displaying the time of the current post in WordPress is done with the template tag the_time(). Formatting the time string can be done with the standard PHP format charachters. The articles below will give you a more detailed explanation of how this works.

The datetime attribute requires an ISO 8601 date. The format character you need for this is c. The second call to the_time() will render the date as July 7th, 2009.

<time datetime="<?php the_time('c'); ?>">
    <?php the_time('F jS, Y'); ?>
</time>

Comments

The same technique can be used for displaying comment dates. Only you will have to use comment_date() in stead of the_time().

<time datetime="<?php comment_date('c'); ?>">
    <?php comment_date('F jS, Y'); ?>
</time>

Top · Tweet about this

Browse Articles

0 Opinions posted so far. Now go post your own. To the comment form!

Commenting is closed for this article.

Subscribe to this blog

About this blog

This is the personal weblog of Jan Vantomme.
I write about the everyday things that move me as a designer. I write shorter things on Twitter.

Add to Technorati Favorites

Some of the blogs I like

PixelPlayground
A blog on Generative Art by Jan Vantomme
Veerle's Blog
A nice blog on graphic design, xhtml and css by Veerle Pieters
Jirka in New York
Life in NY by Jirka Depreter (dutch).
Posh CSS
A nice repository of CSS related articles.
Shaun Inman
A blog on web design and development by Shaun Inman