Friday, June 20, 2008

Fresh Remarks

You want a 'recent comments' section on your blogger blog? Follow these directions and it could happen to you!

1-Get behind the metaphorical curtain on your blog by clicking 'New Post' or 'Customize'
2-Click the 'Layout' tab
3-Click 'Add a Page Element'
4-Pick the 'HTML/JavaScript' option
5-Give it a title. Something original, like, "Recent Comments."
6-Select the following code and copy it in. I didn't write it, I only found it. Willie improved it (if you read it carefully, you'll see his name among the greater-thans, less-thans, and curly braces).
7-Don't bother Willie


<ul><script style="text/javascript">
// Willie 6/12/2008 - slight bug fixes (comments not
//linking correctly), and now capitalizes first letters
//of post titles.
function showrecentcomments(json) {
for (var i = 0; i < 5; i++) {
var entry = json.feed.entry[i];
var ctlink;

if (i == json.feed.entry.length) break;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
ctlink = entry.link[k].href;
break;
}
}

var ptlink = ctlink.split("#");
ptlink = ptlink[0];
var txtlink = ptlink.split("/");
txtlink = txtlink[5];
txtlink = txtlink.split(".html");
txtlink = txtlink[0];
var pttitle = txtlink.replace(/-/g," ");

// capitalize the first letters in the title (Willie)
var names = pttitle.split(' ');
for (var j = 0; j < names.length; j++) {
names[j] = names[j].substring(0,1).toUpperCase() + names[j].substring(1);
}
pttitle = names.join(' ');

pttitle = pttitle.link(ptlink);
if ("content" in entry) {
var comment = entry.content.$t;
}
else if ("summary" in entry) {
var comment = entry.summary.$t;
}
else var comment = "";
var re = /<\S[^>]*>/g;
comment = comment.replace(re, "");

document.write('<li>');
document.write('<a href="' + ctlink + '">' + entry.author[0].name.$t + '</a>');
document.write(' on ' + pttitle);
document.write('<br/>');
if (comment.length < 50) {
document.write(comment);
}
else {
comment = comment.substring(0, 50);
var quoteEnd = comment.lastIndexOf(" ");
comment = comment.substring(0, quoteEnd);
document.write(comment + '...<a href="' + ctlink + '">(more)</a>');
}
}
document.write('</li>');
}
</script>
<script src="http://yourblog.blogspot.com/feeds/comments/default?alt=json-in-script&callback=showrecentcomments">
</script></ul>
<noscript>Unfortunately, we are unable to show you the recent comments at this time.</noscript>



8-Change the green 5 to however many comments you want on your screen at a time.
9-Change the blue 50s to however many characters you want the snippet of comment to be.
10-Change the red yourblog to whatever blog you'd like to monitor (usually it's your own).
11-Save your changes.
12-Go look at your blog and see if anything changed.
13-Send Thad $50. (Paypal accepted)

**In testing this out, I discovered that yourblog.blogspot.com is an actual site, run by a woman named Nancy. If you don't change anything in the code, the comments on her blog will grace your page.

7 comments:

Hosander said...

where, amid the HTML, do I put it?

Thaddeus said...

um...are you trying to do this with your un-upgraded blogger?

When you click on 'HTML/JavaScript' you should get a bar for a title and an empty box beneath it. Just copy it into there.

Hosander said...

I did it, I'm so smart

Nasty Butler said...

Don't bother Willie...good advice.

The Cute One said...

I'm bored with this blog. You should write something new!

Jinx said...

These Remarks are starting to become noticably less-than-fresh.

Kyle and Svet Keeton said...

Thank you for the tip, Willie!

We were struggled with capitalizing the first letters in the title! Now we got it and everything works just great!

Best wishes,
Svet and Kyle