-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite-scroll shows load more button even if there are no more posts #282
Comments
Closing as not enough information provided to diagnose. @kategee Feel free to re-open if you have more information. |
You just have to have an even number of posts, so if the pagination is set to 5, and there are 10 posts, there will be two pages. On the first page, when you click load more, the next 5 posts appear. Now that all 10 are loaded, the load button still appears. The button should not appear on the second page as there is no more posts to load. |
Does it happen on any theme? Are you testing with WP trunk and the latest Jetpack version? |
I'm having the same issue on a custom theme. Though I'm using a standalone version of infinite scroll through the infinite-scroll-from-jetpack plugin, the code causing this behaviour is the same as in the latest Jetpack version. The function is_last_batch() in modules/infinite-scroll/infinity.php checks if the number of fetched posts on a page is smaller than the number of posts to display on a page. So with the example of @kategee, when there are 10 posts in total, and the last page is fetched, the number of fetched posts is 5, just as the number of posts to display on a page. This makes the is_last_batch function return false, while it should return true. It seems to me that the right way to check for the last 'batch' is to multiply the current page (2 for the last page) with number of posts per page (5) and compare this with the total number of posts for the query (10). To check for the last batch, test whether the current_page*posts_per_page is equal to or greater than the total number of posts. After some fiddling around with the code, I came to the following solution: static function is_last_batch() {
$current_page = self::wp_query()->query_vars['paged']+1;
$posts_per_page = self::get_settings()->posts_per_page;
$displayed_posts = $current_page*$posts_per_page;
$total_posts = intval(self::wp_query()->found_posts)+$posts_per_page;
return ($displayed_posts >= $total_posts);
} The only strange thing I encountered is that 'self::wp_query()->found_posts' returns the total number of posts minus the number of posts per page. That's why I've added them again to determine the total number of posts. |
Obviously, the function is_last_batch() (version of Jetpack 4.1.1) in modules/infinite-scroll/infinity.php is totaly wrong. To temporary fix it in a theme I used filter 'infinite_scroll_results'. add_filter('infinite_scroll_results', function($results, $query_args, $wp_query) {
if ($wp_query->get('paged') == $wp_query->max_num_pages) {
$results['lastbatch'] = true;
}
return $results;
}, 10, 3); |
@koscoder same here |
Not sure what this status of this ticket is (or should be), but as of 4.4.2 the issue is pretty-much fixed, and
Now, as I said, it's pretty much fixed. While generally it works ok, the Load More Posts button still appears on the second page, when there are exactly two pages. |
Fixes #247 Using is_super_admin() is discouraged in WP 4.8 and later.
Load more button should not be there unless there are actual posts to load. You have to click the button, it attempts to load more posts, there isn't any, then it disappears.
The text was updated successfully, but these errors were encountered: