Infinite scroll in single post
-
Hi all,
Testing Infinite Scroll in a development environment. I am using a custom theme based on underscores.me starter theme. Infinite scroll is working fine in archive pages (both tag and category) but it doesn’t work on the single post page.
I have a section under the main loop with ‘Read Also’ and want to use there the inf loop.
This is the code from the single.php:<section class="related-posts-container"> <span class="read-also"> <span>Read Also</span> </span> <div id="infinite" class="related-posts"> <?php $categories = get_the_category($post->ID); $catid = $categories[0]->cat_ID; $currpost[] = get_the_ID(); $args = [ 'post_type' => 'post', 'post_status' => 'publish', 'orderby' => 'DESC', 'cat' => $catid, 'post__not_in' => $currpost, ]; $query = new WP_Query( $args ); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); get_template_part('template-parts/infinite'); endwhile; endif; ?> </div> <!--End Infinite Loop --> </section> <!--End Related Posts Container-->
This is the altered code from jetpack.php:
add_theme_support( 'infinite-scroll', array( 'container' => 'infinite', 'render' => 'ths_infinite_scroll_render', 'footer' => false, 'wrapper' => true, 'posts_per_page' => 6, ) );
And the renderer function:
function ths_infinite_scroll_render() { while ( have_posts() ) { the_post(); if ( is_search() ) : get_template_part( 'template-parts/content', 'search' ); else : get_template_part( 'template-parts/infinite', get_post_format() ); endif; } }
Is it because it’s in locahost? Is there something i’m missing on Jetpack setup?
I’ve tried other infinite scroll plugins and they work (with a shortcode though). I’ve tried TwentyTwenty theme and have the same problem.
Please advice.
- The topic ‘Infinite scroll in single post’ is closed to new replies.