List of pages – AJAX load more

Previous Question

That answer I’ve linked to shows the steps you’ll need to take. It probably didn’t come up in your searches as you weren’t using the right terms.

As you’re a front-end dev, this is how I’d do it based on that persons advice.

  • Don’t load anything in the template. Just have an empty ul with an id you can target, and a button to use for the click event.
  • Create a php function, in functions.php, with one parameter (current_list_num) to get 6 posts using get_posts. Use the “offset” parameter to define which 6 to get (current_list_num / 6).
  • Have the button, wherever it is, trigger the ajax call. As part of the ajax, pass in the number of items in the list currently. That will give you the offset needed for the get_posts call.
  • On page load, trigger a click of the button to start the process