Wednesday, January 03, 2007

Recently, I wrote a blog post on how to add a NewsTrust link to a Drupal site. I have now spent a bit of time working on adding a NewsTrust link to Blogger based blogs. It is a bit more complicated with Blogger, since you can’t put PHP into your blogger template.

I should note that this is using the ‘old blogger’ and I haven’t updated to the new blogger. I believe it should work with new blogger as well. Anyone who tries it should let me know.

Since there PHP isn’t available, you need to find a different way of encoding the title and name into acceptable URL formatting. I used javascript to do this.

The three values that I retrieved from blogger are the URL, the Title and the Author. They are <$BlogItemPermalinkURL$>, <$BlogItemTitle$>, and <$BlogItemAuthor$>. I did not use the date variables, <$BlogDateHeaderDate$> or <$BlogItemDateTime$> since they would need to be formatted properly for NewsTrust and it may conflict with the way dates are used in the blog. I also did not use <$BlogItemBody$> which is probably the best way to set the story_quote parameter. In my case, I too often bury my lead, so using the beginning of the BlogItemBody wouldn’t make a great quote.

To make this work, I created a javascript function which I put in the head of my blogger template. Here is the function:

function newstrust(url,title, author)

You will note that I hard coded that it was a Blog Post, from a Blog that is not in the set of listed blogs, and that it’s name is Aldons blog. You will want to change these according to your own needs.

Then, in the Blogger section, immediately before the ItemPage section, I added the following line:

<a href="javascript:newstrust('<$BlogItemPermalinkURL$>','<$BlogItemTitle$>','<$BlogItemAuthor$>')"><img src= alt="Rate on NewsTrust"></a>

So, with this, I now have a Rate on NewsTrust link. Test it out. Let me know how it works, provide any feedback you can, and let me know if you use it on your blog.

Update 11/12/2007: NewsTrust has updated their site, and I've updated this message to reflect the changes. Most importantly, you should now use instead of

In addition, they have added server side javascript to make it easier to add the Newstrust button.

<script type='text/javascript'>
newstrust_icon = '';
<script id="newstrust_button_script" src="" type="text/javascript"></script>

However, I could not get it to work in Blogspot. In addition, on other platforms, this is good for when the visitor has the specific story open, but isn't good for pages that list multiple stories on it.

1 comment:

Ellie K said...

Thank you for coding the News Trust button for old Blogger AND for new Blogger. I'm just about to try it out now on blogger (I just found News Trust, I'd been at Newsvine, which is nice too).

Anyway, I'm going to rate you right now, rather than wait to check if the button works, cause I'll probably forget. Plus you did a lot of work over nearly 3 years, someone should rate you by now!