I would like each post to have a "post to twitter" link/button on it.
Additional, on the home page, where I have snippits of recent posts, it would be nice to add a post to Twitter button/link for each snippet, just below the "Continue reading ..." link.
I've found instructions for how to do this on other Blogging platforms, but not for Movable Type.
Reported on Movable Type 4.2
Not sure if this is what you're looking for but this is how I did it on my website:
Thank you. I'll try it out.
One potential problem is that twitter will not auto shorten long url's.
If you have a bit.ly account (free) you can use their API like this
<script type="text/javascript" charset="utf-8" src="http://bit.ly/javascript-api.js?version=latest&login=BITLY_ID&apiKey=BITLY_API_KEY"></script>
<script type="text/javascript">
BitlyCB.shortenResponse = function(data) {
var s = '';
var first_result;
// Results are keyed by longUrl, so we need to grab the first one.
for (var r in data.results) {
first_result = data.results[r]; break;
}
// Now get the shortURL
shortURL = first_result["shortUrl"];
document.location = "http://www.twitter.com/home/?status=Reading:+" +
escape(document.title) + "+" + shortURL
+ "+{via+@me}";
}
</script>
<img src="./amazing_twitter_graphic.png" onClick="BitlyClient.shorten(document.location, 'BitlyCB.shortenResponse');">
Note: Not my code, taken from a post on the ProBlogger 31 Days to Build a Better Blog forums.
I have actually been looking for something like this myself. However using either escape(document.title) or includes %20 for every space when the page redirects to Twitter.
How do you get rid of the %20 for spaces? Anyone know?
Ken
If you figure it out let me know!
Still trying to figure out how to use Rob Kenny's js example!
Try replacing
with
The only problem is that I need this:
Not document.title. But this is a step in the right direction. Also I tried your above code Rob and no go.
It puts in the + signs in as needed to alleviate the %20, but it just fails to load the page.
Twitter is under DDOS attack at the moment making it difficult to test :)
Thanks all for the tips. I ended up using the TweetMeme.com script. Works well, includes a count of how many times the URL to a post has been tweeted.
Hey Rob, many thanks! I got it working, and yes the 2 days of wonkyness because of the DoS made testing no fun. Check out my code here if you wish:
http://bgviewsnetwork.com/dev/2009/08/setting-up-rewriterules-for-profile-and-tags/
Ken
Here is the script provided by Rob but it now opens in a new window. The only problem is that window.open will not work if Safari is set to block popups. Oddly even if Firefox is set to block the popups, window.open still works.
<script type="text/javascript" charset="utf-8" src="http://bit.ly/javascript-api.js?version=latest&login=BITLYID&apiKey=BITLYAPI"></script> <script type="text/javascript"> BitlyCB.shortenResponse = function(data) { var s = ''; var first_result; // Results are keyed by longUrl, so we need to grab the first one. for (var r in data.results) { first_result = data.results[r]; break; }// Now get the shortURL
shortURL = first_result["shortUrl"];
windowOpenUrl = "http://www.twitter.com/home/?status=" + document.title.replace(/ /g,"+") + "+" + shortURL + "+(via+@example)";
window.open(windowOpenUrl, 'new_window', 'width=600,height=400');}
</script>
<img style="cursor: pointer;" src="/images/tweet_this.gif" title="Tweet about <$MTEntryTitle encode_html="0">" onClick="BitlyClient.shorten(document.location, 'BitlyCB.shortenResponse');">
Hey Rob, many thanks! I got it working, and yes the 2 days of wonkyness because of the DoS made testing no fun. Check out my code here if you wish:
http://www.solicitors-in.co.uk/