WordPress.org

Ready to get started?Download WordPress

Forums

Infinite-Scroll
Possible to get infinite scroll working on single pages? (2 posts)

  1. andy999
    Member
    Posted 1 year ago #

    The problem is, infinite scroll doesn't play well with <php query_posts ?> or so it seems, and since putting your standard wordpress loop on a page <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    just gets the single post, unsurprisingly.

    I mean, take Mashable for example, they use wordpress and after each article on the single page the loop just keeps going, loading in new posts.

    Is it possible to use infinite scroll with query_posts at all?

    http://wordpress.org/extend/plugins/infinite-scroll/

  2. Ismail Fazal
    Member
    Posted 3 months ago #

    Yes, i also got stuck to the same problem.
    I have a solution here, as infinite scroll depends on the next post navigation link

    after putting

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
      // Show post content
    <?php endwhile; else: ?>
    // DO SOMETHING IF NOTHING WAS FOUND
    <?php endif; ?>

    After you did so you also need to specify navigation bar like this
    (you can copy it from your index file, here i have used roots wordpress starter theme)

    <?php if ($wp_query->max_num_pages > 1) : ?>
      <nav class="post-nav">
        <ul class="pager">
          <li class="previous"><?php next_posts_link(__('← Older posts', 'roots')); ?>
          <li class="next"><?php previous_posts_link(__('Newer posts →', 'roots')); ?>
    
      </nav>
    <?php endif; ?>

    More can find here https://gist.github.com/ismailfazal/519f25576fd98d8f828a
    Its all done..

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.