admin管理员组

文章数量:1122832

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

And also looked this one 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

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

Share Improve this question asked May 15, 2016 at 17:03 Amjad AliAmjad Ali 291 silver badge2 bronze badges 5
  • maybe try ajax load more plugin. – majick Commented May 15, 2016 at 17:05
  • Thanks majick I am creating Theme that's why need to create it without plugin. – Amjad Ali Commented May 15, 2016 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 Commented May 15, 2016 at 17:17
  • 1 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 Commented Jan 2, 2018 at 4:10
  • i need to know how we add infinite scroll to load pages not posts. is there ant way kindly guide me. i had the load post code for my website but i want to load pages on scroll or button click. – Cheetah Commented Dec 9, 2020 at 13:41
Add a comment  | 

1 Answer 1

Reset to default 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.)

本文标签: How to create infinte scroll in wordpress for blog and custom post type