-
Hi, I’ve been trying to do the above following the thread here:
https://generatepress.com/forums/topic/adding-a-loading-spinner-to-infinite-scroll/I have the same issue and setting the hook location to
after_primary_content_areadoesn’t show the loading text at all. It only shows it once when usingafter_main_contentlocation.I think the issue is that GP thinks that
after_primary_content_areais the only location where the loader is displayed for the first time. On subsequent infinite scroll requests, it loads the loader on the same location it was first loaded. -
Ok, I think this did the trick!
jQuery( document ).ready( function($) { var $container = $( '#main article' ).first().parent(); var $loader = $('.infinite-loading'); // Cache the loader element for performance // This function moves the loader to the end of the last article function moveLoader() { $loader.insertAfter('#main article:last'); } // Move the loader initially moveLoader(); $container.on( 'request.infiniteScroll', function( event, response, path, items ) { $loader.show(); } ); $container.on( 'append.infiniteScroll', function( event, response, path, items ) { $loader.hide(); moveLoader(); // Move the loader after new items have been appended } ); }); -
Glad to hear that George. And thanks for sharing the answer
-
George
Hey David, sorry for opening this thread again. I am enqueueing this script as usual from the functions.php file. I was wondering if there was a way to add a condition to enqueue the script only when Use infinite scroll functionality is enabled and Use button to load more posts is disabled from the Customizer.
-
Fernando
Hi George,
Try a conditional statement like this:
$settings = wp_parse_args( get_option( 'generate_blog_settings', array() ), generate_blog_get_defaults() ); if( !$settings[ 'infinite_scroll_button' ] && $settings[ 'infinite_scroll' ] ){ //YOUR CODE HERE } -
George
That’s some really cool magic right there, Fernando, thanks!
-
Fernando
You’re welcome, George!
- You must be logged in to reply to this topic.