Reputation: 523
This is the instruction from Tumblr documentation:
Tumblr.LikeButton.get_status_by_page(n)
: Call this function after requesting a new page of Posts. Takes the page number that was just loaded as an integer.
Tumblr.LikeButton.get_status_by_post_ids([n,n,n])
: Request Like status for individual posts. Takes an array of post IDs.
This question has been asked few times with solutions here and here both answers can tell you how to request like button status with post IDs. So is there a easier and probably faster solution?
I'll share how i do it, please share your opinions too.
Upvotes: 2
Views: 1065
Reputation: 523
What's happening in the accepted answer here is:
Now this is how you can request like button status after new page is loaded with page numbers.
Request like button status with page number.
var $initialNumberOfPosts = $('.post').length; // Get number of posts
$('#posts').infinitescroll({
loading: {
msgText: "Loading..",
img: "/loading_image.gif",
finishedMsg: "End!"
},
navSelector : "#pagination",
nextSelector : "#nextpage",
itemSelector: ".post"
},
function(newElements) {
var $currentNumberOfPosts = $('.post').length; // Get current number of posts
var pageNumber = Math.ceil($currentNumberOfPosts / $initialNumberOfPosts); // Get page number
Tumblr.LikeButton.get_status_by_page(pageNumber); // Request like button status
});
*Using (.ceil) because user might have selected 15 posts per page but there can be less than that in the last page.
Update: March 5, 2014.
Their is more simple way to get the page number using Tumblr variable and increase it when the new page loads. Try the following:
Request like button status with current page number.
var pageNumber = {CurrentPage}; // Get current Page number ( Will not work in external file)
$('#posts').infinitescroll({
loading: {
msgText: "Loading..",
img: "/loading_image.gif",
finishedMsg: "End!"
},
navSelector : "#pagination",
nextSelector : "#nextpage",
itemSelector: ".post"
},
function(newElements) {
pageNumber++; // Get page number after new page is loaded.
Tumblr.LikeButton.get_status_by_page(pageNumber); // Request like button status
});
// End update.
*This is an example script for how you can request like button status with Paul Irish's infinite scroll.
So in both way, it's roughly 3 - 4 steps. My solution seems easier to set up for me so i use it. You can use what seems better to you.
I think my solution is faster 'cause it uses simple functions, but that's just what i think; i don't have any evidence for now. Thank you!
Upvotes: 3