Sunday, January 27, 2008

The Changing Tag Line

By now all three of you have probably realized that I like things to change every once in a while: random wallpaper in GNOME or FVWM, random quotations in the Blog, etc. Heck, if I can figure out how to do it, eventually this blog will have a rotating template as well.

The latest bout with randomness is the tagline at the top of the blog. It was inspired by this hack from Stéphane Hamel. I couldn't get that version to run here, possibly because Blogger has changed a bit since the beta version, but I was able to lift Blog U's random quote generator to get the same effect.

So here's the final version of the hack:

  • Log onto the Blogger Dashboard
  • Select Layout => Template => Edit HTML
  • Download the full template: Because you will frak it up.
  • Click the box that says “Expand Widget Templates”
  • Look for the second invocation of the string <data:description> — at least that's what I had to do.
  • Replace the line
    <p class='description'><span><data:description/></span></p>
    by the following
    <p class='description'>
    <script language='JavaScript'>
    //store the quotations in arrays
    quotes = new Array(5);
    quotes[0] = &quot;First Quote&quot;;
    quotes[1] = &quot;Second Quote&quot;;
    quotes[2] = &quot;And So On&quot;;
    quotes[3] = &quot;Changing the number in Array to match the number of quotes&quot;;
    quotes[4] = &quot;and noticing that the array starts with [0]&quot;;
    //calculate a random index
    index = Math.floor(Math.random() * quotes.length);
    //display the quotation
    document.write(&quot;\n&quot;);
    document.write(quotes[index]);
    //done
    </script>
    <noscript><data:description/></noscript>
    </p>
  • Save everything

Note that I've never been able to get this script to accept more that 10 quotations. If someone can tell me why, or how to get around that, I'd be grateful.

0 comments: