Insert a photo message from tumblr into an external site

I am trying to make a gallery of "endless scrolling" to an external website using tumblr photos.

Everything works, but I have a big problem.

My foreach function stops working after the first 20 results. The endless scroll needs pagination, and I need:

  • To get the whole message, not just the first 20
  • A way to count stars from the 21st post and then after the 31st to create pagination

this is php which i use with masonry

<div id="container"> <?php // tag filtrante $tag = 'conceptual'; $api_key = 'the key'; // preleva e decodifica il file (prende solo i post di di tipo "photo") $tumblr = json_decode(file_get_contents('http://api.tumblr.com/v2/blog/nofrillsintown.tumblr.com/posts/photo?api_key=' . $api_key . '&tag=' . $tag)); // scorre tutti i post foreach ($tumblr->response->posts as $post) { // scorre tutte le immagini contenute in un post foreach ($post->photos as $photo) { echo '<div class="item"><a href="'.$photo->original_size->url.'" rel="lightbox"><img src="'.$photo->alt_sizes[2]->url.'" /></a></div>'; }; }; ?> </div> 
+4
source share
1 answer

Use the offset parameter to receive messages after the 20th: https://www.tumblr.com/docs/en/api/v2#posts

 $limit = 10; $page = 1; $url = 'http://api.tumblr.com/v2/blog/nofrillsintown.tumblr.com/posts/photo?api_key=' . $api_key. '&tag=' . $tag; $url .= '&limit=' . $limit. '&offset=' . ($limit * ($page - 1)); 

Since Tumblr allows you to immediately receive 20 messages, you need to make this call several times. You should probably cache the results, and not make a call every time the page loads.

0
source

Source: https://habr.com/ru/post/1438890/


All Articles