Random Thoughts on Web Design & Development

Oncemade

This tutorial will walk you through creating date badges with WordPress and CSS.

Date Badge Sample

Let's start of by adding the necessary markup to render the appropriate date format. Create a DIV element with a class of "entryDate" and three children SPANs with respective classes "postMoth", "postDay", and "postYear".
Add the PHP code to get the post date from the database as shown bellow. For more PHP date format go to http://us.php.net/date

Markup

<div class="entryDate"> <span class="postMonth"><?php the_time('M') ?></span> <span class="postDay"><?php the_time('d') ?></span> <span class="postYear"><?php the_time('Y') ?></span> </div>

Now let's add styles to make it look pretty.

First of all, set the body font-size to 10px or 62.5%. Then go ahead and set the DIV that wraps the post entry to position: relative so the date badge can be positioned relatively to it. Set margin-left to the width of the date badge plus the gap between the post entry. In this sample the margin-left is set to 4.8em.

Absolute position the entryDate and set the left to the same size as the its parent margin-left. After that, set the width to 3.5em. Next, set all the SPANs inside entryDate as block element (The reason why SPANs are being used instead of DIVs is because if the stylesheet is disabled, the date renders nicely in one line). Don't forget to centered align the text.

Change the appearance as needed, I have changed the size of the text to look more like a calendar and I've set its color to blue and white.

CSS

body { font-size: 62.5%; } .post { position: relative; margin-left: 4.8em; } .entryDate { border: 1px solid #999; font-family: Georgia,"Times New Roman", serif; left: -4.8em; line-height: 1; position: absolute; top: 0; width: 3.5em; } .entryDate span { display: block; text-align: center; } .postMonth { text-transform: uppercase; font-size: 1.2em; padding-top: 0.3em; } .postDay { font-size: 2em; } .postYear { background-color: #2358B8; color: #FFF; font-size: 1.2em; padding: 0.3em 0; margin-top: 0.3em; }

Don't forget to checkout the live demo

Demo

Browser Support

  • Firefox
  • Safari
  • Chrome
  • Opera
  • Internet Explore 7 & 8
  • Internet Explore 6
  • Cancel

Comments

leave a comment
  1. thanks for your tutorial,it is useful,good job! the link of this article has been submitted to here in order to share it with more people.

  2. I think you need a copy editor. ;) Thanks for the tip!

  3. are u up for the challenge? :)

  4. OHH I am amazed with it. It is a good thing for my me. Thanks. ^_^

Trackbacks

  1. Graphic Design Links and Tutorials
  2. Create Date Badge with Wordpress and CSS
  3. 60 Useful Wordpress Links, Plugins and Hacks | Armadillo Creative
  4. 60 Useful Wordpress Links, Plugins and Hacks | Designer’s Block
  5. How to Create a Wordpress Date Badge Without using any image . « xss – core ☻
  6. Best Photoshop, html, javascript and php tutorials » Create Date Badge w/ Wordpress & CSS