Infinite Scroll Archive – Manual Trigger

archive.php

<?php

/**
 * Infinite Scroll Scripts
 *
 */
function ea_infinite_scroll_scripts() {

	$base = get_template_directory_uri() . '/assets/js/';
	wp_enqueue_script( 'infinitescroll', $base . 'jquery.infinitescroll.min.js', array( 'jquery' ), '1.0', true );
	wp_enqueue_script( 'manual-trigger', $base . 'manual-trigger.js', array( 'jquery', 'infinitescroll' ), '1.0', true );
	wp_enqueue_script( 'ea-load-more', $base . 'load-more.js', array( 'jquery', 'infinitescroll', 'manual-trigger' ), '1.0', true );

}
add_action( 'wp_enqueue_scripts', 'ea_infinite_scroll_scripts' );

/**
 * Infinite Scroll Button
 *
 */
function ea_infinite_scroll_button() {

	global $wp_query;
	$page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
	if( $wp_query->max_num_pages > $page )
		echo '<a class="hentry load-more" href="#">Load More</a>';

}
add_action( 'tha_content_while_after', 'ea_infinite_scroll_button' );

// Build the page
require get_template_directory() . '/index.php';

load-more.js

jQuery(function($){

 $('.nav-links').hide();
 $('.site-main').infinitescroll({
     loading: {
         finishedMsg: 'Everything has loaded.',
         img: '',
         msgText: 'Loading...',
         behavior: 'twitter'
     },
     nextSelector: '.nav-links .nav-previous a',
     navSelector: '.nav-links',
     itemSelector: '.site-main .hentry'
 });
 $('.site-main').infinitescroll('unbind');
 
 $('body').on('click', '.load-more', function() {
 $('.load-more').remove();
     $('.site-main').infinitescroll('retrieve');
     return false;
 });
 
});

style.css

#infscr-loading {
  color: #C80073;
  font-size: 24px;
  text-align: center;
}

#infscr-loading img {
	display: none;
}

jquery.infinitescroll.min.js

manual-trigger.js

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk