1

I duplicated twentysixteen theme and only changed the name of the folder and the name of the theme in style.css. I then added in functions.php :

function twenty_sixteen_infinite_scroll_init() {
        add_theme_support( 'infinite-scroll', array(
            'container' => 'main',
            'type' => 'click',
            'posts_per_page' => '2',
        ) );
    }
    add_action( 'after_setup_theme', 'twenty_sixteen_infinite_scroll_init' );

The older posts button appears but after I click it no more posts are loading. What am I missing?

On the original twentysixteen the infinite scroll works well.

  • 2
    I think I found the solution. For some reason it needs render regardless of the fact that I have a content.php file. Maybe because it is placed in /template-parts/content.php. So use render property with : get_template_part( 'template-parts/content', get_post_format() ); – Grim Oct 7 '16 at 9:48
0

I added the render and this is the full code.

function mytheme_infinite_scroll_init() {
add_theme_support( 'infinite-scroll', array(
'container' => 'content',
'render' => 'mytheme_infinite_scroll_render',
'container'      => 'content',
'posts_per_page' => 2,
) );
}

function mytheme_infinite_scroll_render() {
while( have_posts() ) {
    the_post();
    get_template_part( 'template-parts/content', get_post_format() );
    }
}

add_action( 'init', 'mytheme_infinite_scroll_init' );

you may find a problem that the pagination is shown and you may solve it by removing it from the theme or give it style display:none

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.