alexcavender / wordpress-ajax-load-more

Load more blog posts with AJAX in WordPress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is this?

This snippet lets you load more blog posts with AJAX in WordPress.

Setup

  1. Add the function inside functions.php to the bottom of your theme's functions.php file
  2. Add the code from index.php to your theme's index.php , directly before <?php get_footer(); ?>

How to Edit the number of posts loaded

By default , the snippet gets the next 10 posts

What if your blog is set up to load 5 of your latest posts?

  1. In the function load_more_posts, change 'posts_per_page' from 10 to 5
  2. In your index.php, inside <script> change offset from 10 to 5, and on line 26 change 10 to 5.

How do I style the blog posts that are loaded?

  1. Everything inside the <article> tag within functions.php can be customized (lines 24-32) Examples include grabbing the post thumbnail via the_post_thumbnail() or any wordpress template tags one would traditionally use.

Will this work with my theme?

  1. 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.

About

Load more blog posts with AJAX in WordPress

License:GNU General Public License v3.0


Languages

Language:PHP 100.0%