infinite scroll loading only last post
-
My JetPack’s infinite scrolling script is loading only the last post everytime I click on the “older posts” button. I think it has to do with the custom things I made to the loop on the index, cause I have two different sections for posts: one, for the latest post (more prominent, with the excerpt showing and other meta data) and second, a ul list of the next 15 posts (just the dates and excerpts).
Could anyone help me get this straight? I’d like infinite scroll to show the next (number of posts set on the reading options) posts when I click the button (err, AKA normal behavior).
This is the code on my functions.php
// infinite scroll function infinite_scroll_render() { get_template_part( 'content-post', 'standard' ); } function anw_infinite_scroll_init() { add_theme_support( 'infinite-scroll', array( 'type' => 'click', 'container' => 'load-more-posts', 'wrapper' => false, 'render' => 'infinite_scroll_render', 'posts_per_page' => 100, )); } add_action( 'after_setup_theme', 'anw_infinite_scroll_init' );
I set “post per page” to 100 to test but it doesn’t matter what number I put in there.
This is my full index.php
<?php get_header(); ?> <section id="intro"> <div class="wrapper"> <h2>About this site</h2> <!-- <p class="tagline">Summary of what this Blog is about</p> --> <p><?php echo get_theme_mod( 'text_option_about', 'default_value' ); ?></p> <p><a href="/about/" title="About this site">Learn more</a>.</p> </div><!-- .wrapper --> </section><!-- #intro --> <?php if (have_posts()) : ?> <?php $count = 0; ?> <section id="last-post"> <div class="wrapper"> <p class="pre-title"><?php echo get_theme_mod( 'text_option_latest', 'default_value' ); ?></p> <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count <= 1) : ?> <h3><a href="<?php the_permalink() ?>" class="permalink" rel="bookmark" title="Permanent link to <?php the_title(); ?>"><?php the_title(); ?></a></h3> <div class="last-post-excerpt"> <?php the_excerpt(); ?> <p><a href="<?php the_permalink() ?>" class="permalink" rel="bookmark" title="Permanent link to <?php the_title(); ?>">Read the full post...</a></p> </div><!-- .post-excerpt --> <div class="post-meta"> <ul> <li class="meta-published"><strong>Published:</strong> <?php the_date('Y-m-d'); ?> @ <?php echo get_the_time(); ?></li> <li class="meta-categories"><strong>Categories:</strong> <?php the_category(', '); ?></li> <li class="meta-comments"><a href="<?php comments_link(); ?>" title="Go to post comments"><?php comments_number( 'No comments', 'One comment', '% comments' ); ?> (add one?)</a></li> </ul> </div><!-- .post-meta --> <br clear="all" /> </div><!-- .wrapper --> </section><!-- #last-post --> <section id="latest-posts"> <div class="wrapper"> <p class="pre-title">More recent posts:</p> <ul> <?php else : ?> <li><a class="permalink" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <span><?php the_time(get_option('date_format')); ?></span> <h3><?php the_title(); ?></h3> <?php the_excerpt(); ?> </a> </li> <?php endif; ?> </ul> <?php endwhile; ?> <?php else : ?> <?php endif; ?> <ul id="load-more-posts"> </ul> </div><!-- .wrapper --> </section><!-- #latest-posts --> <?php get_sidebar(); ?> <?php get_footer(); ?>
Reading settings: 16 posts (in my case, for the latest post and for the ul with the next 15).
And my site is: lozbo.info .
I am not a developer so I don’t even remember how I came with that “solution” for separating the posts, I don’t know if this can be considered “two loops on the same page”, I probably copied or read it in a tutorial, so maybe the solution is simple but it exceeds my (basic) php understanding.
Thanks in advance.
- The topic ‘infinite scroll loading only last post’ is closed to new replies.