31 January, 2007

Fiddling while my blog burns

I've been putting off the switch to the new blogger template system because, like Propter Doc, I've been having trouble getting the expandable post summaries to work properly. Rewriting the javascript which did the trick on my old template to use the new metadata labels, and get past a seemingly much fussier XML parser, proved to be a long exercise in fiddling, but I've finally managed it. For those who are interested, this is the code I used. You have to be in the HTML view with the widgets expanded to insert it:

<script type='text/javascript'>
var memory = 0;
var number = 0;

Then scroll way down the page until you find the div for the post-body and insert the stuff in bold:
<div class='post-body'>
<b:if cond='data:blog.pageType == "item"'>
<script type='text/javascript'>
var permlink='<data:post.url/>';
var title='<data:post.title/>';

var spans = document.getElementsByTagName('span');
var number = 0;
for(i=0; i <spans.length; i++){
var c = " " + spans[i].className + " ";
if (c.indexOf("fullpost") != -1) {

if(number != memory){document.write('<p><a href=' + permlink + '>"'+ title + '" continues...</a></p>') }
memory = number;


<div style='clear: both;'/> <!-- clear for photos floats -->

The bit in brackets in the document.write statement can be changed if you want it to say something different. Now, when you're writing a post, you just stick the bit you don't want to appear on your front page between <span class="fullpost"> and </span>, and off you go!

Note that I didn't write the original code - I've just (I think) bodged it to work in the new system. Here's another way to do it, from someone who looks like he might know what he's talking about, although for some reason I couldn't get that to work either.

I'll be fiddling with other bits of the template in the next few days, so apologies in advance for when I break the HTML (Update: which I see is already the case for IE users. Bloody Microsoft! OK, have fixed it (sort of) although all the posts vanish to the bottom of the page if you shrink the window too much. Seriously, people, get a better browser.

No comments: