How to create infinite scroll in wordpress for blog and custom post type. I have tried jetpack infinite scroll but its not working on custom wordpress page template for custom post type. I looked at this tutorial but it seems old
http://code.tutsplus.com/tutorials/how-to-create-infinite-scroll-pagination–wp-24873
And also looked this one https://github.com/infinite-scroll/infinite-scroll
but this project is no longer maintained.
Please tell me or recommend some new tutorials that are compatible with WordPress 4.5 for create infinte scroll.
Thanks
You probably need to define a new loop function for the Custom Post Type to pass to the render
parameter.
As in the example from https://jetpack.com/support/infinite-scroll/
/**
* Add theme support for infinity scroll
*/
function twenty_ten_infinite_scroll_init() {
add_theme_support( 'infinite-scroll', array(
'container' => 'content',
'render' => 'twenty_ten_infinite_scroll_render',
'footer' => 'wrapper',
) );
}
add_action( 'after_setup_theme', 'twenty_ten_infinite_scroll_init' );
/**
* Set the code to be rendered on for calling posts,
* hooked to template parts when possible.
*
* Note: must define a loop.
*/
function twenty_ten_infinite_scroll_render() {
get_template_part( 'loop' );
}
As you can see you can call a template part within that function to generate the next load of posts to be displayed (Infinite Scroll will update the query for you so you simply need a loop template.)