Infinite Scroll doesn't load posts
-
I have infinite scroll enabled and I put the following code in my functions.php file:
// theme support for Jetpack infinite scroll add_theme_support( 'infinite-scroll', array( 'container' => 'content', 'render' => 'infinite_scroll_render', 'footer' => false ) ); // render function for Jetpack infinite scroll that 2010 uses, the later WP themes don't need this function infinite_scroll_render() { get_template_part( 'post-loop' ); }I have a post-loop.php file that has the template for my individual posts in it.
When I scroll to the bottom of the front page, the scrolling animation appears, but it doesn’t load any posts. I also tried deleting the render portion of the above code and just having it fall back to the default content.php file which didn’t work either. Does anyone know the solution to this?
-
Could you try to follow this tutorial to make sure your template files and your post-loop.php file are built properly for Infinite Scroll to work?
http://ottopress.com/2012/jetpack-and-the-infinite-scroll/Let me know how it goes.
my index.php file has this:
<div id="content"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part('content', get_post_format()); endwhile; else: ?> <p id="no-posts">There's nothing here yet :(</p> <?php endif; ?> </div>my functions.php file has this:
// theme support for Jetpack infinite scroll add_theme_support( 'infinite-scroll', array( 'container' => 'content', 'render' => 'infinite_scroll_render', 'footer' => false ) ); // render function for Jetpack infinite scroll that 2010 uses, the later WP themes don't need this function infinite_scroll_render() { get_template_part( 'post-loop' ); }and my post-loop.php has this:
<?php while (have_posts()) : the_post(); ?> <article class="teaser"> (post contents) </article> <?php endwhile; ?>I don’t see anything that I’m doing wrong?
That indeed won’t work that way. Your loop is already defined in
index.php:if ( have_posts() ) : while ( have_posts() ) : the_post();It then calls
content.php, orcontent-ANYPOSTFORMAT.php. It doesn’t callpost-loop.php, though.If your theme already includes
content.phptemplate files, you could get rid ofpost-loop.phpas well as of theinfinite_scroll_render()function and reference, and use the default Infinite Scroll settings (Jetpack will usecontent.phptemplate files by default, if you specify a rendering function).Let me know how it goes.
I tried getting rid of the infninite_scroll_render() function and the post-loop.php file but for some reason nothing changed. It still shows the loading gif but doesn’t load the posts.
If I rename post-loop.php to content-post.php will it load?
content-post.phpwould never get used, as nopostpost format exists.Does you theme include any
content.phpor content-something.php` file?my theme uses content.php but when I delete the infinite_scroll_render() function it still doesn’t load the posts.
Could you copy the contents of
content.phphere?<?php if ( (!$wp_query->current_post == 1 && is_home() && !is_paged()) || (!$wp_query->current_post == 1 && is_category() && !is_paged()) ) : ?> <article class="teaser" id="first"> <div class="thumbnail" id="first-thumbnail"><a href="<?php the_permalink(); ?>"> <?php the_post_thumbnail('first-thumbnail'); ?></a></div> <div class="content-container"> <h2><a href="<?php the_permalink(); ?>" class="title"><?php the_title() ;?></a></h2> <?php if ( has_excerpt() ) { ?> <p class="excerpt-content"> <?php $myExcerpt = get_the_excerpt(); $tags = array("<p>", "</p>"); $myExcerpt = str_replace($tags, "", $myExcerpt); echo $myExcerpt; ?> </p> <?php } else { echo ''; } ?> <div class="metadata"> <!--<a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><i class="fa fa-user"></i><?php the_author(); ?></a>--> <a href="<?php echo get_post_meta($post->ID, 'source', true) ?>" target="_blank"><i class="fa fa-external-link-square"></i><?php echo get_post_meta($post->ID, 'source-name', true) ?></a> <p><i class="fa fa-clock-o"></i><?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></p> <!-- Category <?php $categories = get_the_category(); $output = ''; if ($categories) { foreach ($categories as $category) { $output .= '<a href="' . get_category_link($category->term_id) . '">' . '<i class="fa fa-thumb-tack"></i>' . $category->cat_name . '</a>'; } echo trim($output, $separator); } ?> /Category --> <a href="<?php the_permalink(); ?>#comments"><i class="fa fa-comment-o"></i><fb:comments-count href="<?php echo get_permalink($post->ID); ?>"></fb:comments-count> comments</a> </div> </div> </article> <?php elseif (is_single()) : ?> <article class="single"> <h2><?php the_title(); ?></h2> <div id="metadata"> <?php get_template_part('single-metadata', get_post_format()); ?> <?php echo sharing_display(); ?> </div> <div class="single-container"> <?php the_content(); ?> </div> <span id="source">source: <a href="<?php echo get_post_meta($post->ID, 'source', true) ?>" target="_blank" id="source"><?php echo get_post_meta($post->ID, 'source-name', true) ?></a></span> <div class="next"> Up Next:  <?php $next_post = get_next_post(); if (!empty( $next_post )): ?> <a href="<?php echo get_permalink( $next_post->ID ); ?>"><?php echo $next_post->post_title; ?></a> <?php endif; ?> </div> <?php get_template_part('single-sharebar', get_post_format()); ?> <?php related_posts() ?> <div id="comments"><?php echo do_shortcode('[fbcomments]'); ?></div> </article> <?php else : ?> <article class="teaser"> <div class="thumbnail"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('small-thumbnail'); ?></a></div> <div class="content-container"> <h2><a href="<?php the_permalink(); ?>" class="title"><?php the_title() ;?></a></h2> <?php if ( has_excerpt() ) { ?> <p class="excerpt-content"> <?php $myExcerpt = get_the_excerpt(); $tags = array("<p>", "</p>"); $myExcerpt = str_replace($tags, "", $myExcerpt); echo $myExcerpt; ?> </p> <?php } else { echo ''; } ?> <div class="metadata"> <!--<a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><i class="fa fa-user"></i><?php the_author(); ?></a>--> <a href="<?php echo get_post_meta($post->ID, 'source', true) ?>" target="_blank"><i class="fa fa-external-link-square"></i><?php echo get_post_meta($post->ID, 'source-name', true) ?></a> <p><i class="fa fa-clock-o"></i><?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></p> <!-- Category --> <!--<?php $categories = get_the_category(); $output = ''; if ($categories) { foreach ($categories as $category) { $output .= '<a href="' . get_category_link($category->term_id) . '">' . '<i class="fa fa-thumb-tack"></i>' . $category->cat_name . '</a>'; } echo trim($output, $separator); } ?> <!-- /Category --> <a href="<?php the_permalink(); ?>#comments"><i class="fa fa-comment-o"></i><fb:comments-count href="<?php echo get_permalink($post->ID); ?>"></fb:comments-count> comments</a> </div> </div> </article> <?php endif; ?>Could you try replacing the first line by the following?
<?php if ( is_home() || is_category() ) : ?>I just replaced the first line like you said and the posts still arent loading, but now every post looks like a “first” post based on the template.
Thanks for giving it a try. At this point, it might be easier if I had access to the theme and could run some tests on a test site of mine. Could you send me a copy of the theme, so I can take a closer look?
Thanks!
How do I send you a copy of the theme? I clicked your link but I don’t know how to attach files with that contact form.
Could you contact us via this contact form and mention this thread? We’ll get back to you and you’ll be able to reply with a zip of the theme.
Another alternative would be to use a file sharing service like Dropbox, upload your theme there, and send us a link to the file on Dropbox.
The topic ‘Infinite Scroll doesn't load posts’ is closed to new replies.