This snippet lets you load more blog posts with AJAX in WordPress.
- Add the function inside functions.php to the bottom of your theme's functions.php file
- Add the code from index.php to your theme's index.php , directly before
<?php get_footer(); ?>
By default , the snippet gets the next 10 posts
- In the function load_more_posts, change 'posts_per_page' from 10 to 5
- In your index.php, inside
<script>
change offset from 10 to 5, and on line 26 change 10 to 5.
- Everything inside the
<article>
tag within functions.php can be customized (lines 24-32) Examples include grabbing the post thumbnail viathe_post_thumbnail()
or any wordpress template tags one would traditionally use.
- This should work with any WordPress theme. Of course, there will be exceptions especially on large themes that have lots of custom code. It has been designed to work out of the box with any underscores based theme.