Monday, March 10, 2008

Tumblr hack: A real tag cloud

Tumblr may come up with "real" tag browsing soon, but meanwhile, here's a tag cloud that -- unlike third party services -- uses the actual tags that you assign to your posts.

Basically, the script calls the Tumblr JSON API and processes the posts, 50 at a time (the maximum allowable; configurable). It saves the tags, URLs, and a bit of the content. If there are any remaining posts, it keeps on doing this until it retrieves all of them, or reaches a preset maximum (150 by default, or thrice). It then renders the tags in varying font sizes depending on the total number of times each tag was used.

By default, links are created for each of the tags. Clicking on a tag will generate a list of posts with that particular tag. [ Hey Tumblr! A /tags/<tagname> path that only shows posts with that tag would be nice. :-) ]

I used Jason Levitt's Dynamic Script Tag class to call the Tumblr API as many times as required.

Here's*** the quick-and-dirty demo script showing the tags from my scifaiku site (again). If you do use it, please send me your URL via a comment. :-)

*** Update: The original one didn't use the titles (I had no titles in scifAI, originally) but instead parsed the content up to the first HTML tag. Here is a more generic one, using post titles.

16 comments:

Greg C. Brown said...

just put it up on mine. cool!

gregcbrown.net

Alex Ibrado said...

Hi Greg! You may want to try this one instead, as the original code was tuned for scifAI. The new one uses the actual post titles as the links. See the tumblrCallback function for changes.

Maia Bittner said...

Hi Alex, I'm working on putting mine up here: http://www.maiaeats.com

Thanks!

Todd said...

Hey Alex -

First off, thanks so much for putting this together!

Now, on to the business at hand... I'm trying to get this up and running at http://tumble.toddlevy.com/ and it's not quite working.

It'll only return 3 or 4 posts at most. I tried messing with CLOUD_JSON_NUM and CLOUD_JSON_MAX to no avail.

In fact, as best I can tell, CLOUD_JSON_NUM isn't ever used in the code. And if I set CLOUD_JSON_MAX to 0, I get a 503 error from Tumblr.

Any help appreciated.

TL

Camilo said...

Hi
I'm using your tag cloud, too.
And I've the same problem as Todd!
Thanks for any help

Benvenga

i like jesus buns said...

Hey thanks for this neat script: i spent a bit of idle time tooling around with it on my page, and created a crappy hack that puts a tag blurb at the bottom of posts as well. Now if there was some way to do it on the dashboard, i feel like a dumba**, but still, it was fun to play around with:

http://modx.tumblr.com/post/43313433/enjoy-the-tags-or-else

Hatch said...

Bug Report :-D

Find this line:
cloud_request = new JSONscriptRequest(CLOUD_JSON_URL + '?callback=tumblrCallback&type=regular&start='+cloud_done+'&num='+CLOUD_JSON_MAX);

And change CLOUD_JSON_MAX to CLOUD_JSON_NUM.

Also, the script only shows text posts. If you aren't getting very many results, maybe you don't have very many text posts.

joegasper said...

Thanks!

I've updated mine to

1) include all tags from all types of posts (remove "type=regular" from buildCloud function) and,

2) set the tags to be links to the list of your posts with that tag.

' +cloud_tags[i]+ ' ';

Active here:
http://reactorboy.tumblr.com

toddlevy said...

@joegasper: THANK YOU!

Tag cloud is finally working as desired on my site!

See it in action here...
http://tumble.toddlevy.com

Peteski said...

got it (sort of) kind the way I want it.

http://hotwheels.tumblr.com/

thanks.

p4tr1ck said...

Just got it all figured out.

http://p4tr1ck.tumblr.com

NuttyKnot said...

Thanks a lot!
I put it up on my blog
http://nuttyknot.com

parneix said...

Hi,

I was using your script on Tumblr and it was working great. Until recently : it just disappeared. No more cloud. I didn't mess with the code. At first I thought I must have create too much tags, but people are telling me there is no limit on the number of tags you can create. Any idea? And thanks for the hard work.

chadanuk said...

http://dan.blogs.steamshift.com/

Kosha said...

I think I am a confused novice, but where is the actual HTML script to add to my tumblr?

Thanks!

gascomm said...

help an idiot out.

ive got the script working fine to a point - but how do i get it to break out of the sidebar when displaying a post for a clicked tag?

just click any tag http://gascomm.tumblr.com/ to see my problem