Grab Tumblr posts
To avoid implementing entire OAuth flow, Tumblr_grabbr uses Tumblr API v1. Please note that this lib can be broken any time when they decide to deprecate old API.
- Laravel 1.5.x
- cURL
- Copy tumblr_grabbr.php to libraries folder
-
fetch 10 posts from demo.tumblr.com using cache (if available)
$page = Input::get('page', 1); $data = Tumblr_grabbr::grab('demo', $page, 10); if ($data){ ... }
-
You can turn off cache by passing 4th argument
FALSE
$data = Tumblr_grabbr::grab('demo', 1, 10, FALSE);
-
Configured your Tumblr using your own domain?
$data = Tumblr_grabbr::grab('http://yourwebsite.com', 1, 5);
-
fetch single post from demo.tumblr.com
$post = Tumblr_grabbr::grab_one('demo', 192341); if ($post){ ... }
$data = Tumblr_grabbr::grab('demo', 1, 10);
return View::make('blog_listing')->bind('data', $data);
In your blog_listing.php view file, play with $data['posts']
foreach ($data['posts'] as $post)
{
// print_r($post);
}
Tumblr_grabbr utilizes Laravel's Paginator
class.
$data = Tumblr_grabbr::grab('demo', 1, 10);
if ($data['pagination')
{
echo $data['pagination']->links();
// ...or...
// echo $data['pagination']->previous();
// echo $data['pagination']->next();
}
Tumblr_grabbr::grab
adds summary
and thumbnail-url
property to every text type post.
- The First two paragraphs(
<p>
) becomessummary
(if available) - URL of the first image(
<img>
) becomesthumbnail-url
(if available)
this is the reason why I made Tumblr_grabbr :/