[Resolved] InfiniteScroll

Home Forums Support [Resolved] InfiniteScroll

Home Forums Support InfiniteScroll

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #980366
    Mathieu

    Hi Tom,

    I am trying to setup Infinite Scroll so that it fills my need.

    I have two questions :

    1) Is it possible to have an infinite InfiniteScroll on the cellphone but an InfiniteScroll with a loading button on the desktop? Because a page reload is annoying on mobile but a page that never stops is super annoying on the desktop.

    I am trying to find a balance for the users.

    2) I want to be able to load some javascript at the moment of the reload. Do you have any event hook that would allow that?

    Best regards,

    #980785
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    1. First, set the infinite scroll button to true, then add this PHP:

    add_filter( 'option_generate_blog_settings', function( $settings ) {
        if ( wp_is_mobile() ) {
            $settings['infinite_scroll_button'] = false;
        }
    
        return $settings;
    } );

    2. You could use some javascript like this:

    jQuery( document ).ready( function($) {
        var $container = $( '#main article' ).first().parent();
    
        $container.on( 'append.infiniteScroll', function( event, response, path, items ) {
            // Done loading new posts.
        } );
    } );

    Let me know if you need more info ๐Ÿ™‚

    #981246
    Mathieu

    Hi Tom,

    For the point 1), I am sure it would work if I was serving WordPress live, but I have a few level of caching, so the first person who visit the site would get to decide if it scrolls or not and that would change from page to page.

    Surely, there’s a Javascript variable that I could modify? The button is easy to hide on mobile with a media query css if it comes to that.

    Regards,

    #981452
    Tom
    Lead Developer
    Lead Developer

    I just looked into this, and I’m not seeing a JS/CSS way to do it, unfortunately. The script checks for the existence of the load more button. If it exists, the script requires you to click on it. If it doesn’t exist, it will auto-load the posts.

    I suppose we could try changing the class name of the button with JS, but I don’t think it will work.

    Let me know if you want to give it a shot.

    #989256
    Mathieu

    Well, I try and it didn’t work lol but I succeed in doing what I wanted with point 2) which was the most important.

    Thanks a lot again Tom!

    Regards,

    #989302
    Tom
    Lead Developer
    Lead Developer

    No problem. I’ll look into this to see if it’s something we can make easier ๐Ÿ™‚

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.