Support » Fixing WordPress » Next_and_Previous_Links lead to blank page.

  • Resolved henballs

    (@henballs)


    Hi guys, I’m trying to put on the bottom of my page “older blog posts” to navigate users to older posts. I’m using:

    <?php echo get_next_posts_link('Go to next page'); ?>

    And the link appears, but it goes to a blank page. How do I fix this?

    Here’s my index.php

    <div class="post-container">
          <?php query_posts('posts_per_page=3&offset=3'); if (have_posts()) : ?>
          <?php while (have_posts()) : the_post(); ?>
            <div id="blog-posts" <?php post_class() ?>>
              <?php the_post_thumbnail( array(180,180) ); ?>
              <h2>
                <a href="<?php the_permalink() ?>">
                  <?php the_title(); ?>
                </a>
              </h2>
              <?php the_excerpt(); ?>
              <span class="entry-date"><?php echo get_the_date(); ?></span>
            </div>
          <?php endwhile; ?>
          <?php echo get_next_posts_link('Go to next page'); ?>
          <?php endif; wp_reset_postdata(); ?>
        </div>
        <?php get_sidebar(); ?>

Viewing 11 replies - 1 through 11 (of 11 total)
  • Moderator keesiemeijer

    (@keesiemeijer)


    moderator


    Setting the offset parameter overrides/ignores the paged parameter and breaks pagination:
    http://codex.wordpress.org/Function_Reference/WP_Query#Pagination_Parameters
    http://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination
    http://codex.wordpress.org/Pagination

    Why do you use “offset”. Do you have multiple loops on that page?

    Hi Kessie, I’ve two loops. I’m using offset so that the first loop is always going to be my 3 newest post. and the second loop is always going to be the “Rest” of my posts.

    I’m doing this because I want to edit the first loop’s CSS to “feature” my newest posts.

    If offsetting isn’t the best way to do this (cause it breaks paginaton, how should I approach this problem? How could I find the solution?

    Moderator keesiemeijer

    (@keesiemeijer)


    moderator


    Do you want to have two loops on all paginated pages as well, or just the first page?
    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

    Just the first page. I’m trying to make my index page have this structure:

    First loop:
     Newest post #5
     Newest post #4
     Newest post #3
    
    Second loop:
     Older post #2
     Older post #1
     (See older posts link) Etc.. keeps going till the oldest post.
    Moderator keesiemeijer

    (@keesiemeijer)


    moderator


    You could do it with one loop and no query. Something like this:

    <!-- start of loop -->
    <?php while ( have_posts() ) : the_post(); ?>
    <!-- first three posts on the first page -->
    <?php  if ( !is_paged() && ( $wp_query->current_post <= 2 ) ) : ?>
    
    <?php  if ( $wp_query->current_post == 0 ) : ?>
    	<div class="first_three_container">
    <?php endif; ?>
    
    <!-- do stuff for first three posts  -->
    
    <?php  if ( $wp_query->current_post == 2  ) : ?>
    	</div> <!-- end first_three_container -->
    <?php endif; ?>
    <?php else : ?>
    
    	<!-- do stuff for the rest of the posts -->
    
    <?php endif; ?>
    <?php endwhile; ?>

    That kind of works, but it’s giving me an infinite loop I think.

    My posts keep getting loaded and reloading and scrolls infinitely now.

    Moderator keesiemeijer

    (@keesiemeijer)


    moderator


    please post the full code of what you have so far – see the Forum Rules for posting code.

    Sorry there’s actually not an infinite loop. The problem is it seems that the get_next_post() at the end is not appearing.

    <?php get_header(); ?>
    
    <!-- start of loop -->
    <?php while ( have_posts() ) : the_post(); ?>
    <!-- first three posts on the first page -->
    
    <?php  if ( !is_paged() && ( $wp_query->current_post <= 2 ) ) : ?>
    
    <?php  if ( $wp_query->current_post == 0 ) : ?>
      <div class="first_three_container">
    <?php endif; ?>
    
    <!-- do stuff for first three posts  -->
    <div class="post" <?php post_class() ?>>
        <?php the_post_thumbnail( array(280,280) ); ?>
        <h2>
          <a href="<?php the_permalink() ?>">
            <?php the_title(); ?>
          </a>
        </h2>
        <?php the_excerpt(); ?>
    </div>
    
    <?php  if ( $wp_query->current_post == 2  ) : ?>
      </div> <!-- end first_three_container -->
    <?php endif; ?>
    <?php else : ?>
    
      <!-- do stuff for the rest of the posts -->
    <div id="blog-posts" <?php post_class() ?>>
        <?php the_post_thumbnail( array(180,180) ); ?>
        <h2>
          <a href="<?php the_permalink() ?>">
            <?php the_title(); ?>
          </a>
        </h2>
        <?php the_excerpt(); ?>
        <span class="entry-date"><?php echo get_the_date(); ?></span>
    </div>
    <?php endif; ?>
    <?php endwhile; ?>
    <?php echo get_next_posts_link('Go to next page'); ?>
    Moderator keesiemeijer

    (@keesiemeijer)


    moderator


    Hey it worked thanks so much for the help!

    Moderator keesiemeijer

    (@keesiemeijer)


    moderator


    You’re welcome. I’m glad you’ve got it resolved 🙂

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Next_and_Previous_Links lead to blank page.’ is closed to new replies.