video

The world becomes a fascinating place when viewed in super incredible insane slow motion… 

Feb
24
2011
text

How to use Tumblr as a simple and flexible content management system

First off, apologies to my regular readers; this post is going to be far geekier and techier than most stuff I blog about.

This is a tutorial on how use the Tumblr API to embed content into a website (in other words, use it as a simple CMS.) It’s aimed at people like me, designers/front-end developers who know HTML and CSS but don’t have the programming chops to build our own databases.

(This is just boring background-y stuff; skip to below if you just want the code/tutorial)

I do occasional freelance web work, mostly on projects for individuals or small businesses. In other words, people who want a custom site but are also on a limited budget. The problem that has started to crop up over and over again in the past year (for me, at least) is that everyone wants easy-to-update, dynamic content on their pages, but they don’t want a crappy template site and they don’t want to pay a programmer to build something for them.

As non-programming-type people, that leaves us with a few options: Wordpress, Joomla, and Drupal. The few times I’ve had to mess with Drupal and Joomla, I’ve found them to be completely counterintuitive and very frustrating. Using them makes me go:

Wordpress, on the other hand, I love. The system is super-intuitive if you know HTML, and can make you feel like a total PHP god(dess) even though you totally aren’t. The problem: the client has complete control over each post, and it’s amazing what kind of trouble they can get themselves into if you leave them alone with a WYSIWYG editor for long enough…

I knew there had to be a better solution. I also knew that Tumblr had an API, and with the ability to post different types of content (photos, videos, links, text, etc), that gave it a lot more versatility than Wordpress. The problem was, I only sort of know what an API is, much less how to to make it do what I want. I spent a long time searching the intrawebs for a tutorial. I found this, which was a good jumping off point, but had the problem of only returning one post, no matter what I tried.

So that’s when I enlisted the help of a very kind and patient programmer friend, and he helped me mess around with the code until we got it right AND he explained what each and every line meant, so I could fix it myself in the future. He only made fun of me and threatened to post my embarrassing php/life analogies on Reddit two or three times. Swoon.

Anyhoo, figured this information might be useful to some other designers out there, so I’m sharing it with y’all:

STEP 1. Get the content you want

You first need to get the XML feed with the correct data. Lets start by calling everything:

http://kelmo.tumblr.com/api/read

Except, obviously, you’ll want to replace my Tumblr name with your own. If you have a custom URL it might look like this:

http://blog.kellymorr.com/api/read

This should come out looking like code vomit on your page. That’s good! You’re doing it right!

From here you can decide to pull data by post type, post number, tags, etc.

http://blog.kellymorr.com/api/read?type=photo&tagged=Fantastic%20Stuff

This will pull all of the data from my site for any photo posts that are also tagged “Fantastic Stuff” (note: if your tag is separated by a space, just put a %20 in its place)

You can also decide how many posts you want, and were to start.

http://blog.kellymorr.com/api/read?type=photo&tagged=Fantastic%20Stuff&start=0&num=3

This will get me the three most recent posts (starting at post “0”). Just as a note, I believe Tumblr limits the total number of posts you can call at any one time is 50.

I’m sure you see the pattern now: to the end of your XML feed just at a ? then the thing you want to call. Separate multiple calls by &s. BAM!

STEP 2. Learn to speak barf

Look at your XML feed.

Now back at me.

Now back at your XML feed and right-click to view the source code.

Okay, so it may still appear to be code-barf, but it’s now slightly more comprehensible code-barf. You’ll start to notice there are bits in angle brackets <these things>? And they’re all nesty and cozy inside of each other? Maybe you’ll notice they look a little something like this?

Gooooood.

Super Smart Programming Friend informs me that these things are called “elements.”

Now, if we look inside our elements, we’ll notice that sometimes there’s some additional information hanging out as well:

<post id="1224936338" url="http://blog.kellymorr.com/post/1224936338" url-with-slug="http://blog.kellymorr.com/post/1224936338/hmm-maybe-i-should-think-about-going-back-to" type="photo" date-gmt="2010-10-02 01:16:50 GMT" date="Fri, 01 Oct 2010 18:16:50" unix-timestamp="1285982210" format="html" reblog-key="KuaSEPKv" slug="hmm-maybe-i-should-think-about-going-back-to" width="1882" height="1086">

In this case, our element would be the post, and all the things partying in post’s hot tub (url, url-with-slug, type, date-gmt, etc) are called “attributes.”

These elements and attributes are the different bits of data that we can call. Now that we can speak their language, they are our friends!

STEP 3. Puts the content where you wants it

In the words of my hero, Bob Ross, now all we have to do is create ourselves a happy little PHP document. Do a happy little copy-paste of the below. FTP that shiz. And now you should have something that looks somewhat like this Example. (Minus all the fancy styling, which I obviously spent hours and hours slaving over.)


<?php
$tumblrfeed = 'http://blog.kellymorr.com/api/read?type=photo&tagged=Fantastic%20Stuff&start=0&num=3';
$tumblrfeed = simplexml_load_file($tumblrfeed);

foreach($tumblrfeed->posts->post as $blog){
	$caption = $blog->{'photo-caption'};
	$url = $blog->{'photo-url'};
	$date = $blog->attributes()->date;

	echo "<li><div class='picture'><img src='$url' /></div><div class='info'>$caption<p>Posted: $date</p></div><div class='clear'></div></li>";	

}
?>

WOW! Magic! But even more awesome, I’m now gunna ‘splain to you what it all means, so you can customize it as you see fit.

$tumblrfeed = 'http://blog.kellymorr.com/api/read?type=photo&tagged=Fantastic%20Stuff&start=0&num=3';

This line is saying that we’re going to create something called “$tumblrfeed” and it’s going to be everything found at that XML URL we designated earlier. (I’m gunna go ahead and assume you know to put your own url in here…)

Essentially $ signs are used as naming devices in PHP; from here on out, anywhere you see a $blah, you’re free to hilariously change it to $boogers, $farts, $boobies, $etc and it will have no negative impact, as long as you’re consistent.

$tumblrfeed = simplexml_load_file($tumblrfeed);

Well now PHP knows he’s looking at something, he’s just not quite sure what yet. So, in this line, we tell him that he’s looking at an xml load file. Now he knows how to interact with little $tumblrfeed there. Aw, how cute.

foreach($tumblrfeed->posts->post as $blog){

So now we’re going to start going through and picking out what we want. We’re going to look through all that $tumblrfeed code-barf, and we’re going to see that there’s an element called “posts”, and nested within “posts” is another element called “post”. We’re going to call that post $blog. Furthermore, we’ll notice that there is more than one “post” in our $tumblrfeed, so we use the foreach to tell us to pick them all out and call them all $blog.

$caption = $blog->{'photo-caption'};
$url = $blog->{'photo-url'};

Now we’re going to search through the posts ($blog->) and find anything that’s in a <photo-caption> element and we’re going to call it $caption. Similarly, we’re going to go through the posts and find all the <photo-url> elements and call them $url.

$date = $blog->attributes()->date;

Lastly, we’ve decided we want to get the date. Now, if we look back at our code-barf, we realize that the date is an attribute, not an element. Same concept, just slightly tweaked. We look through element post (which, remember, we named $blog), then look through the attributes of $blog to find “date”.

echo "<li><div class='picture'><img src='$url' /></div><div class='info'>$caption<p>Posted: $date</p></div><div class='clear'></div></li>";

Finally, the echo prints out our content how we want it. Feel free to use whatever html you want and to style it however you want. Wherever you want to put the information you called above, just put in the $hilarioustitle you designated.

STEP 4. There is no step four

That’s it! Now you/your clients can easily upload a “video of the day” or update lists of articles that they’ve written, with little chance that they’ll end up with a white, 4px-tall h1 tag in lieu of a line break.

If you want, you can even incorporate javascript, so it’s all pretty-licious. Hopefully this helps someone out there… I know I’ll be using it more in the future.

Oct
6
2010
link
Do you write like a girl?

Apparently I do about 70% of the time… Oddly, my pieces with male protagonists were declared overwhelmingly “female” compared with my pieces that had female protagonists.  

I’d be curious to see how other peoples’ work is analyzed.  Check out the Gender Genie and post your results!

(If you’re curious, the text above apparently has a female score of 142 and a male score of 24.)

Sep
24
2010
photo
Just when I thought I was jaded and beyond impressing, my iPhone somehow managed to blow my mind again.
I just deposited a check into my bank account without leaving my living room.  All I had to do was take a picture of the front and back and magic of the intrawebs made me (vaguely) richer!!!  I was pretty sad when WaMu got taken over by Chase a couple years ago, but this one app has pretty much single handedly changed my mind.  I ♥ Chase!  Until they charge me some ridiculous overage, of course, then I&#8217;ll likely write a much complainey-er blog post about them.  Until then: if you have an iPhone + Chase, download their mobile app.  It will help you be so much lazier! 

Just when I thought I was jaded and beyond impressing, my iPhone somehow managed to blow my mind again.

I just deposited a check into my bank account without leaving my living room.  All I had to do was take a picture of the front and back and magic of the intrawebs made me (vaguely) richer!!!  I was pretty sad when WaMu got taken over by Chase a couple years ago, but this one app has pretty much single handedly changed my mind.  I ♥ Chase!  Until they charge me some ridiculous overage, of course, then I’ll likely write a much complainey-er blog post about them.  Until then: if you have an iPhone + Chase, download their mobile app.  It will help you be so much lazier! 

Jul
27
2010
photo
Nerdtastic: in the Starbucks a half block from wwdc. One developer already updating his code. Everyone else on their iPhone or laptop following the liveblogging of what&#8217;s going on inside. Back to that myself now ;)

Nerdtastic: in the Starbucks a half block from wwdc. One developer already updating his code. Everyone else on their iPhone or laptop following the liveblogging of what’s going on inside. Back to that myself now ;)

Jun
7
2010
video

Hipstamatic is my favorite new app for my iPhone!  It costs only $1.99 and makes taking photos fun again, because you never know quite what you’re going to get.  Select a vintage film stock, your favorite lens, and decide if you need a flash or not.  Just enough options to get you hooked (and make you want to buy the expansion packs… which I’ll probably be doing before spring break.)

The app loads a little slowly (which has caused me to miss a few choice photo opportunities) and has kind of a groan-worthy name, but it takes good photos and has a well designed interface to make you feel like you really are holding an old-school camera.  Overall, I love the concept and it’s quickly become one of my top ranked/used iPhone applications.

Feb
27
2010
link
Foreverscape

Lots of posts to catch up on after a crazy few weeks… In the meantime thought I’d pass along this amazing website a long-lost friend from high school created and sent to me.  87 feet of hand drawn art all linked together and scrolling on the intrawebs.  Pre-tay pre-tay cool.

Feb
2
2010
Posted in:
Comments
link
Text "Haiti" to 90999 to automatically donate $10 to the Red Cross

Donate by text is probably one of the most unique and helpful mobile innovations to come around in the last year or so. I first learned of it in December when listening to my weekly podcast of This American Life. Ira Glass implored listeners to donate just $5 to help keep the podcast on the air. What made it so great and easy to do, however, was that I could donate at that exact minute - while I was out walking around a farm in Broomfield, Colorado with only my iPhone and a few cows to keep me company - and the charges would simply go on my monthly mobile phone bill, which is set up to automatically deduct from my bank account. No remembering to sign online when I got home. No entering of my credit card number into yet another website. Simple, easy, and safe.

This innovation has also recently been used to help the earthquake victims in Haiti. I’ve been meaning to donate since it happened, but kept forgetting until I found out I could donate via text. I sent them two messages and added my own meager $20 to the relief. I imagine many people have done similarly, people who in the past were well intentioned but never quite remembered to go to the Red Cross’ website after a long day at the office. So far the texting generation has raised $22 million to support the disaster relief! And if you’d prefer to donate to another organization, they accept text donations, as well. Click the link above to be taken to an article with more information.

Jan
18
2010
photo
Okay, I get the concept of the Window&#8217;s 7 ads: Let&#8217;s appeal to average people and show that we listen to our customers (and fixed the abysmal aborted fetus that was Window&#8217;s Vista&#8230;)  But I totally don&#8217;t get their billboard ads.  One features a woman making a really retarded face as she steps into the traffic, and this one features a guy mid french-fry bite.  Is it because average people eat French Fries?  I mean, maybe&#8230; but why couldn&#8217;t it have just been a guy sitting at a table with a plate of fries in front of him?  This photo is a remarkably unattractive photo of a moderately attractive guy.  I feel that if this photo were tagged of him on Facebook, he would untag himself.  So why on earth was this deemed giant-billboard material?
Ergo, my Mac makes me happy.

Okay, I get the concept of the Window’s 7 ads: Let’s appeal to average people and show that we listen to our customers (and fixed the abysmal aborted fetus that was Window’s Vista…)  But I totally don’t get their billboard ads.  One features a woman making a really retarded face as she steps into the traffic, and this one features a guy mid french-fry bite.  Is it because average people eat French Fries?  I mean, maybe… but why couldn’t it have just been a guy sitting at a table with a plate of fries in front of him?  This photo is a remarkably unattractive photo of a moderately attractive guy.  I feel that if this photo were tagged of him on Facebook, he would untag himself.  So why on earth was this deemed giant-billboard material?

Ergo, my Mac makes me happy.

Dec
10
2009
text

Why I hate “private” Facebook gifts

This is one of those things I hate myself for hating, but I just felt the need to rant. I think “private” Facebook gifts are evil!

For those not “in the know,” on Facebook you have the option of sending your friends “gifts” which post to their profiles. Each gift costs somewhere between zero and $1 and shows a cute little icon of your choosing and a personalized message. When you send a gift, you have the option of sending it as a public, private, or anonymous message.

Public messages can be seen by everyone and show the senders name next to the gift, anonymous gifts are, well, anonymous, and private gifts show up on the user’s profile as “private” - the recipient knows who sent it but no one else does, nor can they see the message.

Evil

Private gifts just irk me because they’re basically a way of saying “I have something I want to say to a person, and I want you to know that I have something to say to them, but you can’t know what it is.” I imagine these gifts smiling evil little grins then turning their backs on me to gossip with their other little mean gifty friends. Grr.

And, yes, I am quite aware of the stupidity of my hatred. And even more aware that this is something that really only bothers me because there is a specific person who has the power to make me very jealous and upset by doing something so minute and silly. But it still bothers me.

If you have something private to say, send an email or make a phone call or drop a note in the old tree trunk over on McGilacutty’s farm, but don’t send a Facebook gift!

I’ve decided that private fb gifts are silly and amateurish and below me. Well, they are now at least… not like I’ve ever sent one privately with the express knowledge that it would likely bother someone else…

At any rate, I’ve decided to grow up and have made the exceedingly adult decision to only send public Facebook gifts from here on out. I know, I am such a better person for it. This is a magnanimous huge step forward for man kind. Won’t you join me in my selfish and pointless protest?

Jan
13
2009