Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't Work Past Page 2 #141

Open
ghost opened this issue Oct 8, 2017 · 1 comment
Open

Doesn't Work Past Page 2 #141

ghost opened this issue Oct 8, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 8, 2017

Implementing on Wordpress. Works for page 1 and 2, but doesn't go farther. Scroll down to bottom, I should see a footer and pagination. I only see the footer. There are no plugins active on my site. Has anyone run into this?

// infinite scroll 
add_action( 'wp_enqueue_scripts', 'load_jscroll' );

function load_jscroll(){
    wp_enqueue_script('jscroll', get_stylesheet_directory_uri().'/js/jquery.jscroll.js', array( 'jquery')  );
}

function infinite_scroll() {
    global $avia_config;
        echo '<script type="text/javascript">
            jQuery( ".content" ).jscroll( {
            loadingHTML: "Loading...",
            padding: 20, 
            nextSelector: "span.current + a",
            contentSelector: ".post-entry",
            autoTrigger: true
        } )
        </script>';
}
add_action( 'wp_footer', 'infinite_scroll' );
@alex-nick
Copy link

alex-nick commented Dec 11, 2017

My guess that maybe the trigger (nextSelector) is outside of the contentSelector.

The next link should be inside the posts container, like this:

<div class="posts-container">
    <div class="post">Post here...</div>
    <div class="post">Post here...</div>
    <div class="post">Post here...</div>
    <a href="/page2/">Next page</a>
</div>

The following code works for me:

$('.site-main').jscroll({
    contentSelector: '.post-listing',
    nextSelector: '.posts-navigation a:first'
});
<main id="main" class="site-main">

    <?php
    if ( have_posts() ) : ?>

    <div class="post-listing">

        <?php
        while ( have_posts() ) : the_post(); ?>

            <?php
            get_template_part( 'template-parts/post/content', 'entry' ); ?>

        <?php
        endwhile; ?>

        <nav class="posts-navigation" role="navigation">
           <?php next_posts_link('Next Entries','') ?>
        </nav>

    </div>

    <?php
    else :

        get_template_part( 'template-parts/content', 'none' );

    endif; ?>

</main>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant