metafizzy / infinite-scroll

📜 Automatically add next page
https://infinite-scroll.com
7.41k stars 1.74k forks source link

Problem with descending pagination. #913

Closed bilalmalkoc closed 3 years ago

bilalmalkoc commented 4 years ago

My pagination list is descenging and it looks like this:

<!-- In main page -->
<ul>
<li><a href="/comment-page-75" class"prev page-numbers">Previous Comments</a></li>
<li>...</li>
<li>...</li>
<li>...</li>
</ul>

<!-- In first paginated page (comment-page 75) -->
<ul>
<li><a href="/comment-page-74" class"prev page-numbers">Previous Comments</a></li>
<li>...</li>
<li>...</li>
<li>...</li>
<li><a href="/comment-page-75" class"next page-numbers">NextComments</a></li>
</ul>
.
.
.

This is my infinite-scroll code:

$('.commentlist').infiniteScroll({
    path: '.prev.page-numbers',
    append: '.review',
    history: false,
    debug: true,
});

In first scroll it appeds successfuly from comment-page-74. But in second it is fetching from next page (comment-page-75) and appending page 75's comments. It must go previous page (73) but it is not.

Also i check /comment-page-74 and .prev.page-numbers link is "comment-page-73". Links are correct but why your script fetch from next page instead of previous?

By the way, i fix it with using custom path function like this:

path: function () {
    let maxNumber = 75,
    pageNumber = maxNumber - this.loadCount;
    return full_url + '&cpage=' + pageNumber;
},

But i want to use with pagination html. Can you please help me?

desandro commented 3 years ago

But i want to use with pagination html.

Your solution to set path with a function is the appropriate solution.

path: function () {
    let maxNumber = 75,
    pageNumber = maxNumber - this.loadCount;
    return full_url + '&cpage=' + pageNumber;
},

Sorry, you cannot use path set to a selector. When set to a selector, path increments ascending-ly.