/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $tumblog = 'username'; // change to your username // if your Tumblog is self hosted, you need to change the base url to the location of your tumblog $baseurl = 'http://' . $tumblog . '.tumblr.com'; $request = $baseurl . '/api/read/json'; // Tumblr JSON doesn't come in standard form, some str replace needed // parameter 'true' is necessary for output as PHP array $content = $value['posts']; $blogInfo = $value['tumblelog']; // the number of items you want to display $item = 10; // Echo the blog info echo "<h3><a href=\"" . $baseurl . "\">" . $blogInfo['title'] . "</a></h3>\n"; echo "<h4>" . $blogInfo['description'] . "</h4>\n<hr />\n"; // then loop the blog contents for($i=0;$i<$item;$i++){ // we need to find out what the post type is, so we can format it appropriately // first check to see if it is a regular post if($content[$i]['type'] == "regular"){ // echo title if($content[$i]['regular-title'] !== ""){ echo "<p><a href=\"" . $content[$i]['url-with-slug'] . "\">" . $content[$i]['regular-title'] . "</a></p>\n"; }else{ // otherwise use the slug echo "<p><a href=\"" . $content[$i]['url-with-slug'] . "\">" . ucwords(str_replace("-"," ",$content[$i]['slug'])) . "</a></p>\n"; } // then echo the body // grab the string length of the post if($postlength > 120){ // if it's greater then 120, echo the first 120 characters and then add a read more link echo "<a href=\"" . $content[$i]['url-with-slug'] . "\">Read more</a></p>\n"; }else{ // echo the whole body if it's under 120 characters echo $content[$i]['regular-body']; } echo "<hr />\n"; // then check if it's a link }else if($content[$i]['type'] == "link"){ // if it has a title, use that as the title if($content[$i]['link-text'] !== ""){ echo "<p><a href=\"" . $content[$i]['link-url'] . "\">" . $content[$i]['link-text'] . "</a></p>"; // otherwise, just use the link as the title }else{ echo "<p><a href=\"" . $content[$i]['link-url'] . "\">" . $content[$i]['link-url'] . "</a></p>"; } // then echo the description if it has one if($content[$i]['url-description'] !== ""){ echo $content[$i]['link-description'] . "\n"; } echo "<hr />\n"; // then check to see if it's a quote }else if($content[$i]['type'] == "quote"){ // echo the quote echo "<p>" . $content[$i]['quote-text'] . "</p>\n"; // then the source if it has one if($content[$i]['quote-source'] !== ""){ echo "<p>-" . $content[$i]['quote-source'] . "</p>\n"; } echo "<hr />\n"; // then check to see if it's a photo }else if($content[$i]['type'] == "photo"){ // I know it's not valid to not to specify the width and height, but I was having issues without making them the original size echo "<p><a href=\"" . $content[$i]['url-with-slug'] . "\"><img src=\"" . $content[$i]['photo-url-250'] . "\" alt=\"" . $content[$i]['slug'] . "\" /></a></p>\n"; echo $content[$i]['photo-caption']; echo "<hr />\n"; // then check for audio }else if($content[$i]['type'] == "audio"){ echo "<embed " . $audioPlayer . " />"; echo $content[$i]['audio-caption']; echo "<hr />\n"; // then check if it's a video }else if($content[$i]['type'] == "video"){ // Tumblr uses JS to render video hosted by them echo "<script src=\"http://assets.tumblr.com/javascript/tumblelog.js\"></script>"; echo $content[$i]['video-player']; if($content[$i]['video-caption'] !== ""){ echo $content[$i]['video-caption']; } echo "<hr />"; } } // end for ?> <p><a href="<?php echo $baseurl;?>">Read more posts.</a></p>