Skip to content

Instantly share code, notes, and snippets.

@sguzik
Created November 7, 2011 20:12
Show Gist options
  • Save sguzik/1346017 to your computer and use it in GitHub Desktop.
Save sguzik/1346017 to your computer and use it in GitHub Desktop.
Brooklyn Ink Tumblr Mods (real code)
<?php
$url = 'http://thebrooklynink.tumblr.com/api/read/'; //where you can find the posts
$xml = simplexml_load_file($url); //parse the tumblr API to get an object containing all of your posts
$i = 0; //create a counter
foreach( $xml->posts->post as $post ){ //create loop to process individual posts
if ( $i < 1 ) { //check that the loop hasn't run before
if ( $post['type'] == 'regular' ) { //check what kind of post we're dealing with
$post_title = $post->{'regular-title'}; //create a variable to store the title
$post_body = $post->{'regular-body'}; //create a variable to store the body
$post_excerpt = substr( strip_tags($post_body),0,320 ); //substring the body text to get your excerpt (while simultaneously removing all html)
echo '<h3 class="here-is-brooklyn-hed">' . $post_title . '</h3>'; //output your formatted title
echo '<p class="here-is-brooklyn-text">' . $post_excerpt . '...</p>'; //output your formatted excerpt
} elseif ( $post['type'] == 'photo' ) {
$post_photo_src = $post->{'photo-url'}[5]; //create a variable to store the photo source (specifically, the small square one)
} elseif ( ETC ) {
ETC
} else {
echo 'YOU MESSED UP!';
}
$i++; //shorthand for $i = $i + 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment