/ Published in: PHP

Embed Tumblr posts the easy way. Import the xml, split by post-type and seperate the different types of content. I had a hard time finding an easy way to do this and ended up mixing and matching info from 2 very helpful places (check the url\'s in the src) and a co-worker who\'s better versed in PHP than me.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php //http://stocklamp.tumblr.com/post/274675902/putting-your-tumblr-posts-on-your-websites-the-easy-way //http://finlay.tumblr.com/post/529010691/embed-tumblr-into-your-website //http://www.tumblr.com/docs/en/api#api_read $posts = $xml->xpath("/tumblr/posts/post"); foreach($posts as $post) { ?> <div class="post post-<?php echo $post['type'] ?>"> <?php if ($post['type'] == 'regular') { ?> <div class="post-title" id="post-<?php echo $post['id'];?>"><a href="<?php echo $post['url-with-slug']; ?>"><?php echo $post->{'regular-title'}; ?></a></div> <?php } ?> <?php if ($post['type'] == 'conversation') { ?> <div class="post-title" id="post-<?php echo $post['id'];?>"><a href="<?php echo $post['url-with-slug']; ?>"><?php echo $post->{'conversation-title'}; ?></a></div> <?php } ?> <div class="post-body"> <?php if ($post['type'] == 'regular') { <?php echo $small_post . ' …'; } ?> <?php if ($post['type'] == 'quote') { ?> <?php echo $post->{'quote-text'}; ?> <?php echo $post->{'quote-source'}; ?> <?php } ?> <?php if ($post['type'] == 'photo') { ?> <?php echo $post->{'photo-caption'}; ?> <?php echo $post->{'photo-set'}; ?> <?php echo $post->{'photo-url-500'}; ?> <?php echo $post->{'video-source'}; ?> <?php echo $post->{'video-player'}; ?> <?php } ?> <?php if ($post['type'] == 'link') { ?> <?php echo $post->{'link-text'}; ?> <p><a href="<?php echo $post->{'link-url'}; ?>"><?php echo $post->{'link-url'}; ?></a> <?php echo $post->{'link-description'}; ?> <?php } ?> <?php if ($post['type'] == 'conversation') { ?> <?php echo $post->{'conversation-text'}; ?> <?php } ?> <?php if ($post['type'] == 'video') { ?> <?php echo $post->{'video-caption'}; ?> <?php echo $post->{'video-source'}; ?> <?php echo $post->{'video-player'}; ?> <?php } ?> <?php if ($post['type'] == 'conversation') { ?> <?php echo $post->{'audio-caption'}; ?> <?php echo $post->{'audio-player'}; ?> <?php echo $post->{'audio-plays'}; ?> <?php } ?> </div><!-- //end post-body --> <p><a class="more" href="<?php echo $post['url-with-slug']; ?>">» Read more</a></p> </div><!-- //end post--> <?php } ?>
URL: http://stocklamp.tumblr.com/post/274675902/putting-your-tumblr-posts-on-your-websites-the-easy-way
Comments
