Endless Scrolling pathParse for reverse WordPress Comments

I am using the jQuery Infinite Scroll plugin - https://github.com/paulirish/infinite-scroll/ to display my WordPress page comments.

The plugin works fine when viewing comments from old to new (I think this is the default option), but if the following values ​​are set in the discussion options in WordPress:

Break comments into pages with [XX] top level comments per page and the
[LAST] page displayed by default

Comments should be displayed with the [NEWER] comments at the top of each page

Then endless scrolling no longer works.

Looking at the problem, it seems that if the options are as above, then the first comment page that WordPress will display is the last, therefore i.e.

WordPress 1st comment page displayed = http://MYLINK/comment-page-5
WordPress 2nd comment page displayed = http://MYLINK/comment-page-4
WordPress 3rd comment page displayed = http://MYLINK/comment-page-3

and etc.

, Infinite Scroll , ( 5) Infinite Scroll 6, .

IS, pathParse, , , . 100%, .

( ) , .

0
3

, ( ) .

@M1ke .

,

, -, pathParse, , :

.infinitescroll({
    state: {
      currPage: 4 // The number of the first comment page loaded, you can generate this number dynamically to save changing it manually
    },        

    pathParse: function(path,nextPage){
        path = ['comment-page-','#comments'];
        return path;
    }
});

(jquery.infinitescroll.js .min version), , , . , :

// increment the URL bit. e.g. /page/3/
opts.state.currPage++;

// decrement the URL bit. e.g. /page/3/
if (opts.state.currPage > 1) {
    opts.state.currPage--;
}
else if (opts.state.currPage == 1) {
    console.log("Last Page"); // Just needed for debugging              
    opts.state.currPage = 999999; // stop IS from loading Comment Page 0 by giving it a page number that won't exist and will return a '404' to provide 'end' function.
}

, , :

this._debug('pathParse manual');
return opts.pathParse(path, this.options.state.currPage+1);

:

this._debug('pathParse manual');
return opts.pathParse(path, this.options.state.currPage);
0

Id . , , ( ) . . Php ( )

if (!function_exists('iweb_reverse_comments')) {
function iweb_reverse_comments($comments) {
    return array_reverse($comments);
    }   
}
add_filter ('comments_array', 'iweb_reverse_comments');

, js , . , Wordpress > .

+2

URL- div.navigation a:first. href ajax . jQuery , ; , , HTML, .

2

; page=3, - page-3. , , pathParse, ( , ):

 ,pathParse:function(path,nextPage){
   path = path.match(/page[-=]([0-9]*)/).slice(1);
   return path;
 }

, , , , , - 493 ( dev- WP)

opts.state.currPage--;
0
source

All Articles