Problem with infinite scroll on multisite with custom query

Infinite scroll usually requires some kind of Javascript library to load more results via Ajax. The basic idea is this:

  • User arrives at your page, you show, say, 5 posts per page
  • They scroll past a certain offset and you use JavaScript to trigger an Ajax request
  • Your request passes the requested paged, the endpoint receives the request, and returns just the HTML of the posts you want.
  • You handle the Ajax response and insert the HTML in to the page

Here is a good writeup from Smashing Magazine on how to determine if infinite scrolling, pagination, or “Load More” is best for you.

Some other tips:

  • You probably don’t want to load all posts at once – this may not be an issue now, or for a long time, but eventually this will come back to bite you
  • There are plenty of plugins and tutorials for doing this, you just need a good understanding of how it works