15 How to create a calendar widget for your blog
Monday, October 8, 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: | | | | |




15 comments:

March 19, 2009 at 12:25 AM Corinne Rodrigues said...

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

March 26, 2009 at 2:01 AM 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.

March 26, 2009 at 8:45 PM 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,

March 30, 2009 at 11:31 PM 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?

May 5, 2009 at 11:49 AM 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

May 10, 2009 at 6:15 AM Trader said...

Same.

Did closely follow the instructions but no results...

May 10, 2009 at 6:17 AM Trader said...

Same.

Did properly follow the instructions but no results.

May 10, 2009 at 6:23 AM Trader said...

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

Sorry.

May 22, 2009 at 3:56 AM 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?

June 7, 2009 at 3:40 AM 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

June 7, 2009 at 4:00 AM JiangJia Awangzaba Rinpoche said...

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

June 16, 2009 at 3:27 PM Didi said...

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

http://didizekid.blogspot.com/

July 25, 2009 at 12:56 PM 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

August 4, 2009 at 1:45 PM
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.

August 5, 2009 at 4:13 PM 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

Post a Comment