48 How to create a calendar widget for your blog
October 08, 2007 /

In this template, I use a calendar style widget to display the posting date of my posts. This style has recently cropped up in many Web 2.0 style Wordpress blogs, and is easily reproduced in Blogger layouts blogs too. Here I will show you how to create your own calendar widgets to feature at the top of each post.

This Blogger hack uses a combination of javascript, CSS and some slight modification to your template to display the date a post was published over a calendar-style background. There are only three main steps to change your date header to a calendar widget, so don't worry if my explanation seems rather complicated! Here is what you should do:

  1. First, go to Settings>Formatting, and change the date header format to YYYY-MM-DD like this: This enables the script we will be using to correctly parse the date header format.
  2. Next, go to Template>Edit HTML and ensure you have checked the "expand widget templates" box. Now, find the <data:post.dateHeader> section in the posts widget (if you search for "dateHeader" you should be able to find this quickly).
    The "data:post.dateHeader" line may also be wrapped in headings tags (eg: <h2> or <h3> etc.). Instead, we need to wrap this in <div> tags with a class of "date-header", so the line will look like this:
    <div class="date-header"><data:post.dateHeader/></div>
    . Once you have changed this line, save your template.
  3. Finally, open up the Edit HTML section again (no need to expand widget templates this time). Just before the closing </head> tag, add this section of code:
    <!-- calendar widget -->
    <script src='http://bloggerbuster.com/scripts/fastinit.js'/>
    <script src='http://bloggerbuster.com/scripts/prototype-1.5.0.js'/>
    <script src='http://bloggerbuster.com/calendar.js'/>
    <link href='http://bloggerbuster.com/calendar.css' rel='stylesheet' type='text/css'/>
    <!-- end calendar widget -->
    Save your template and view your blog to see the new calendar widget in place!

I originally found a tutorial for this Blogger hack over at Orangevolt which uses a script to parse date headers wrapped in <H2> tags. However, I decided to modify both the code and the image used which ensures greater flexibility over where the widget can be placed.

Customizing the calendar widget

If you would prefer to customize the calendar widget to suit your own taste and style, you can do this by modifying the CSS styling used for this hack.

There are two ways of doing this: you can either download the CSS file, modify and upload to your own server, or copy the styling below into the b:skin section of your template to change the style from within the template itself.

This is the styling I used for the calendar widget:

span.cal {
background:transparent url('images/calendar.jpg') no-repeat scroll 0%;
float:left;
margin-right: 10px;
height:36px;
width:35px;
font-family:"Helvetica",Tahoma,Arial;
font-size-adjust:none;
font-style:normal;
font-variant:normal;
font-weight:normal;
}
span.cal_month {
color:#FFFFFF;
display:block;
font-size:10px;
line-height:11px;
margin-left:1px;
padding-top:1px;
text-align:center;
text-transform:uppercase;
}
span.cal_day {
color:#999999;
display:block;
font-size:18px;
line-height:18px;
margin-left:1px;
padding-top:4px;
text-align:center;
text-transform:uppercase;
}
.sidebar {
margin-bottom: 20px;
}
As you can see, there are many ways the calendar widget may be styled, including:
  • The image background (use the full url if you decide to change this image!)
  • The height and width of the calendar icon
  • The alignment of the calendar (change "float: left" to "float: right" if you would prefer the widget to appear on the right of the page, for example).
  • The font and text sizes
plus many more examples than I can list here.

I would suggest that it is better to link to a css file on an external server than to use this styling inside the template. This is because I often noticed problems with the styling in Internet Explorer when I experimented with the styling in the b:skin area. There seem to be no problems at all when linking to the external style sheet.

You may also like to experiment with the positioning of the date header in your template. In this blog for example, I placed the date header code directly before the post title section, which ensures it appears to the left of the post title.

Why doesn't the calendar appear on some of my posts on the main/archive pages?

The date header will only appear on the top most item which is posted on a given day. So if you post say, three times in a single day, only the newest post will feature the calendar widget. So far, I haven't figured out a way to make this appear for each and every post!

Note: This post has now been edited to correct an error in the code which may have prevented this hack from working in your blogs. I do apologize for this problem guys! Everything should work fine for you now!

Please let me know what you think of the calendar widget by leaving your comments and opinions below.

Technorati Tags: | | | | |

48 Comments:

19 October 2007 21:17 Nirmalya Nag said...

Many Thanks. I am using this in my blog after I found your tutorial.

21 October 2007 00:11 zakirahzakaria said...

Thanks so much.
I'm actually browsing for a sidebar calendar widget for my blog when I stumbled upon your tutorial. But this one is also very helpful.

21 October 2007 00:26 Amanda said...

You're both very welcome :)

Sometime next week, I'll be uploading some different colored "calendars" you could use instead of this default Grey one if you prefer. If anyone has any color preferences, do let me know.

Thanks,

Amanda

4 November 2007 05:04 Bill A said...

Great stuff, Thanks!

Since you asked about color prefs, I'd like a blue one that matched with my black and blue blog at http://billspondering.blogspot.com.

11 November 2007 16:50 Angel said...

Amanda, the calendar can appear if the javascript is used for timestamp.

5 January 2008 14:39 Heather said...

Hi Amanda,you can ignore the email I sent you earlier. I found your tutorial just after I sent it :) Thank you SO much for this, this is the first time I have been able to get a calendar thing to work for me. Your instructions were clear and complete. I would also love this in blue, if you decide to do that.

Happy New Year!

1 February 2008 19:31 adam said...

Does anyone have any ideas why this widget wouldn't work in IE ?
I've gone over the instructions many times, and I still can't get it to work in IE 6 or 7, yet it looks fine in FF and Safari.

2 February 2008 07:15 Bobby said...

Hi. This is a great tutorial by the way, thanks so much.
Only one problem, the date text isnt aligning properly with the image,the text is farther right than the image. I haven't changed any of the css except for the background image. Do you know of an easy solution?
Thanks alot in advance
Heres my url:
http://www.testlayout-bobspotdesign.blogspot.com/

2 February 2008 12:28 Amanda said...

For Adam,

I just emailed you about this widget. To be honest, I noticed a few problems displaying background images in IE these past few days. For some unknown reason, shorthand background statements don't work as they previously did, and I wonder if this is part of the problem..? I'll do some more research and will write this up shortly.

For Bobby,

Wow, I love your design! Did you also download the CSS for the background image? If so, the best way to modify this would be to decrease the margin to the left of the month and date statements in the style sheet. It may be necessary to make these negative numbers (eg: margin-left: -5px).

If you need some help, feel free to send me your files and I'll fix this for you ASAP then send you the files back.

Best wishes,
Amanda

5 March 2008 14:58 Nurlea Laurielle said...

thanks for a great tutorial. However, need to verify with you regarding this (i know u havent found the way to have the calendar widget to appear on each post but really hope u could help me out as I have more than one entries per day and this keeps on showing on the other entries posted on one same day..

Orangevolt Calendar : Parsing date ' ' using pattern '/(\d\d\d\d)-(\d\d)-(\d\d)/' failed.<- in red font, at the position where the calender widget is supposed to be. Why is this happening?

10 March 2008 22:58 Vanessa Alexander said...

Hi Amanda,

Wanted to just say thanks for the date calendar. Its up and working at a new site where I used a really nice new Template that did not have code for author, date etc...It happens.

Anyway I managed to code the author stuff in but still could not get the date in the thing. So I came here and found your calendar. I like this work around better. It was flawless.

Thanks, your hard work is a blessing.

Vanessa

29 March 2008 16:14 Heather said...

Hi Amanda, I am just wondering if you have uploaded other color options for this cool calendar? I would love one in blue! Thanks.

16 April 2008 19:00 Nancy Beck said...

Any color options for the calendar widget? I just installed the gray one, and although it's okay, I'd prefer one in color - blue would be my choice (as it seems to be everyone else's choice on this post, lol).

Thanks for such a great site! :-)

17 April 2008 21:23 JoHnNy said...

tks for the calendar ;)
nice job :)

and i have a question, the bug with IE? any news?

i have it working on first displayed post, but not the following.. :(

14 May 2008 03:39 ikeL said...

thanks for this calendar widget! it looks good in my blog and i love it! your post is really useful! Keep it up and more power! :)

25 May 2008 19:42 PhillyChief said...

If I put it on the left, how can I create a space between it and the Post Title? Right now if I put it on the left, it's flush up against the title.

Thanks for this. I found this on another site but it didn't work. I think it's because they didn't say to change the h2 class to div class. After doing that, it worked!

27 May 2008 21:17 Amanda said...

For Phillychief:

You could try adding these lines of code just before the closing </b:skin> tag in your Blogger template:

span.cal {
margin-right: 10px;
}

Preview your blog before saving just to make sure this works for you :)

Chances are, if you've used the script from another site, the author may not have attached a CSS file to the widget (the one I've posted uses CSS to prevent this happening), but hopefully these few lines of code should solve the problem for you.

Best wishes,

Amanda

23 July 2008 10:15 PC WRECKER said...

i made it. im sure all of us who get the code have the same colors..lol can u make a calendar for us? thanks

18 August 2008 08:11 piratasdaprotasio said...

Wonderful. Did the changes in my test blog first. Soon I'll update my real blog!
Thank you very much!

Patricia Anzanello

18 August 2008 13:03 chanteuse sanders said...

Amanda, right?
The calandar post date didn't work for a few of my posts and showed this really annoying text instead:

Orangevolt Calendar : Parsing date ' ' using pattern '/(\d\d\d\d)-(\d\d)-(\d\d)/' failed.

Help! Here's my blog address:

http://hellolurve.blogspot.com

27 August 2008 03:03 Mga Kwentong ma Alamat said...

Thanks for this widget it work nicely in my page.

Thanks a lot

17 September 2008 07:35 chilly said...

Hello! Thanks for this, it works great. It's the one feature I have wanted that Wordpress has.
One question, When I edit the installed CSS, it will not change anything. What is the reason I can't and is there something I can do to change stuff?
Thanks!

http://onthebricks.blogspot.com

9 October 2008 09:55 MIRELA said...

HI AMANDA..I USE YOUR TEMPLATE AT.www.reduceri-imbracaminte.blogspot.com and i saw today my template was changed..i mean the bookmark button was changed in share button..why this?? when u change the template html this change appers in my template too??? plss send me an mail and explane me..plss

13 December 2008 00:44 Rachel said...

Hi, Amanda -- I used this hack on the Minima template (changed the h2 line as suggested) but it isn't showing up at all. Any suggestions?

24 December 2008 05:18 sassymrs said...

Thank you so much! I was finally able to get the widget to work. Your fabulous!

19 March 2009 07:25 Corinne Rodrigues nee Campos said...

Amanda - Help! This doesn't seem to work for me.....
Corinne

21 March 2009 05:21 Corinne Rodrigues nee Campos said...

Hi Amanda - I used this in your template at http://www.everydaygyaan.com and it didn't seem to work.....any suggestions?

Regards

Corinne
PS: Incidentally your blog is fantastic - I've blogrolled it.
PPS: I changed the date format back again.

26 March 2009 05:52 Windy said...

Hello Amanda,

Thank you for your script. It works at my blog except for one small area.

There is a black bar in the background. It wasn't there before I placed the script in the template.

Could you tell me what I have possibly done wrong to have caused that black background bar to appear.

I would not wish to display the black bar background.

Blog URL is : http://www.lainyonline.com/

26 March 2009 09:01 Windy said...

Hi Amanda,

Please ignore my earlier Comment regarding how to fix the black background behind the Date widget.

I was able to hide the black background by using "transparent" in the CSS code at my template.

Just as an aside - the black background is caused the the Div for the Class.

All's well that ends well.

Thank You once again.

27 March 2009 03:45 Windmill said...

Hi! Amanda,

May I know why after uploading the CSS file to my webhost and initiating my webhost link for it at my blogspot template, it does not display the calendar date.

However, when I return to use the link that you provide, the calendar date is displayed.

Please advise. Thank You,

31 March 2009 07:31 Kyle said...

Amanda, I'm another coding-blonk with not much idea what I'm doing.

But I can't get your widget to work, though I think I followed your instructions properly.

Is it possible for other page elements to interfere with the widget?

5 May 2009 19:49 gray-dots said...

Can't seem to work for my blog.. It just display the date and didn't do any formatting

For example : 2009-05-06

10 May 2009 14:15 Trader said...

Same.

Did closely follow the instructions but no results...

10 May 2009 14:17 Trader said...

Same.

Did properly follow the instructions but no results.

10 May 2009 14:23 Trader said...

Finally it did work but this isn't what I was looking for.

Sorry.

22 May 2009 11:56 Micho said...

Hello Amanda. Your calendar is working great on my blog (rowerowewypady.blogspot.com). But still I have one question. Is there possibility to change the name of month? My blog is in polish and I would like to use polish month names. How can I do that?

7 June 2009 11:40 Bess said...

Amanda,

I tried everything, but because i'm using Minima Stretch, it doesn't even post the date at the top. I can't get anything to appear even after I followed your scripts.

I'm not familiar with css, but I tried moving things around, and it still didn't work. Instead it gave me the following warning at the top of each post:

Orangevolt Calendar : Parsing date ' ' using pattern '/(\d\d\d\d)-(\d\d)-(\d\d)/' failed.

Please help. thanks. bess.fung@gmail.com

7 June 2009 12:00 JiangJia Awangzaba Rinpoche said...

Please help. Script not working on blog.
http://GreatCompassionBodhi.blogspot.com

16 June 2009 23:27 Mohammed said...

i just want to change the color of the calendar from grey to blue....how can i do that??

http://didizekid.blogspot.com/

25 July 2009 20:56 tarak brahmi said...

Hi Amanda,
great efforts! But there is a small problem as chanteuse mentioned:
When we post more than one post a day, we have this message on the blog:"
Orangevolt Calendar : Parsing date ' ' using pattern '/(\d\d\d\d)-(\d\d)-(\d\d)/' failed."
It would be great if you can help with removing this message at least..
I appreciate your nice tips.
Keep up the good work

4 August 2009 21:45 Ash said...

Hello Amanda I have uploaded the js files on my a/c & linked back to them, however the date is showing only for 1 or 2 posts in the calendar format whenever there are more than 2 posts. THis happens even when all posts have different dates. Please help me. This happens even when I link the iles from ur server.

6 August 2009 00:13 John Tertullian and Contra Celsum said...

Hi, Amanda
I too have the problem with "Orangevolt Calendar" message. Would appreciate any help removing this.
jtertullian@gmail.com

16 October 2009 12:19 Tracy said...

Hi,
i am looking for a calendar to add as a gadget to my blog (not a post header) prefereably with a month view and dates with content (such as events) bolded and able to be viewed by clicking on. Have you got any ideas??? Thanks!

26 November 2009 08:43 AC said...

I also have the problem with Orangevolt Calendar : Parsing date 'Wednesday, November 25, 2009' using pattern '/(\d\d\d\d)-(\d\d)-(\d\d)/' failed.

Email me at alcurtsinger@hotmail.com

28 December 2009 03:56 DocuMaker said...

This webpage is prompting people to give you their twitter username and password.

2 February 2010 17:48 Aakash Pathak said...

Not working even after several tries!! :(
http://thepagesofmind.blogspot.com/

12 February 2010 14:38 PHOTOSKIASI.com said...

For some reason it doesn't work any more.
I got a JS error, i think the scripts URLs are no longer valid

22 February 2010 23:02 Bradley said...

Amanda:

The links to all the scripts are not working. Surfing to them directly shows a godaddy hold page. Could you please provide a link where we might download the files for hosting on our own homepage? Thanks.

Post a Comment

Browse through the Archives

All existing posts are still available to view while I'm working on the site, albeit seen in a much simpler interface. Feel free to browse through the archives to find tutorials, templates and articles to help you build a better blog:

Blog Archive

© Blogger Buster 2010 Home | About | Contact | Hire Me