2

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

  • maybe try ajax load more plugin. – majick May 15 '16 at 17:05
  • Thanks majick I am creating Theme that's why need to create it without plugin. – Amjad Ali May 15 '16 at 17:10
  • Sorry, but this is a very broad and widely discussed problem - there is no "one size fits all" solution. If you're coding a theme, you should be sufficient in PHP/JavaScript to roll your own. If you get stuck with something in particular, then come back with your code and we'll be happy to help. – TheDeadMedic May 15 '16 at 17:17
  • here's a good walkthru: rudrastyh.com/wordpress/load-more-posts-ajax.html ajax-loadmore plugin is alright, but has code-bloat in the ajax generated output. – admcfajn Jan 2 '18 at 4:10
0

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.