- This topic has 9 replies, 2 voices, and was last updated 1 year, 6 months ago by
Tom.
-
AuthorPosts
-
December 21, 2020 at 9:33 am #1589662
Arthur
I have a homepage with multiple loops. The last loop is repeating posts every time you scroll to the bottom of the page. Here’s the code from that loop:
<div id="primary" <?php generate_do_element_classes( 'content' ); ?>> <main id="main" <?php generate_do_element_classes( 'main' ); ?>> <h2>Latest Stories</h2> <?php /** * generate_before_main_content hook. * * @since 0.1 */ // Exclude posts that have already been added. //$args3['offset'] = 1; $args3 = array( 'post__not_in' => $added_ids, ); $tier3 = new WP_Query($args3); do_action( 'generate_before_main_content' ); global $added_ids; if ( generate_has_default_loop() ) { if ( have_posts() ) : while ( $tier3->have_posts() ) : $tier3->the_post(); generate_do_template_part( 'index' ); if ($wp_query->current_post !== 0 && ($wp_query->current_post+1)%3 == 0) { if (function_exists ('adinserter')) { echo adinserter (1); } } endwhile; /** * generate_after_loop hook. * * @since 2.3 */ do_action( 'generate_after_loop', 'index' ); else : generate_do_template_part( 'none' ); endif; } /** * generate_after_main_content hook. * * @since 0.1 */ do_action( 'generate_after_main_content' ); ?> </main> </div>
December 21, 2020 at 11:26 am #1589770Tom
Lead DeveloperLead DeveloperHi there,
Any sort of pagination on a page with multiple loops is going to cause issues in WordPress. It’s something I’ve played with quite a bit, and there is no easy solution that I know of, unfortunately.
Infinite scroll in this case looks for posts inside the post container on
/page/2
(and so on), and will load those posts into view as you scroll.In this case, there are multiple loops inside the post container, so all of those posts will load each time new posts load.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 21, 2020 at 12:12 pm #1589815Arthur
Ok that is a bit unfortunate. Any recommendations? I would hate to have to switch themes at this point.
December 22, 2020 at 10:59 am #1591054Tom
Lead DeveloperLead DeveloperRecommendations to have multiple loops and pagination all work together? I don’t think this a theme thing – it’s a WordPress loop/pagination thing.
You could try using a plugin for the infinite scroll functionality – perhaps they’ve worked out a solution: https://wordpress.org/plugins/ajax-load-more/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 23, 2020 at 7:34 am #1592168Arthur
Ok thank you Tom.
December 23, 2020 at 11:17 am #1592406Tom
Lead DeveloperLead DeveloperNo problem – let me know if you do find a solution, I’d love to integrate it with GPP.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 23, 2020 at 11:47 am #1592435Arthur
As far as the page limit, I removed the default pagination links:
remove_action( ‘generate_after_loop’, ‘generate_do_post_navigation’ );
and then output a simpler pagination structure, using ‘next_posts_link’ , which accepts a page limit argument:
<nav id=”nav-below” class=”paging-navigation”>
<?php next_posts_link( ‘« Older Entries’, 5 ) ?></nav>
December 24, 2020 at 10:53 am #1593479Tom
Lead DeveloperLead DeveloperAnd that fixed the issue?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 24, 2020 at 11:15 am #1593507Arthur
Yep
December 26, 2020 at 12:57 pm #1595107Tom
Lead DeveloperLead DeveloperInteresting – thanks for letting us know! 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.