WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Next_and_Previous_Links lead to blank page. (12 posts)

  1. henballs
    Member
    Posted 1 year ago #

    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(); ?>
  2. keesiemeijer
    moderator
    Posted 1 year ago #

    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?

  3. henballs
    Member
    Posted 1 year ago #

    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?

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    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

  5. henballs
    Member
    Posted 1 year ago #

    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.
  6. keesiemeijer
    moderator
    Posted 1 year ago #

    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; ?>
  7. henballs
    Member
    Posted 1 year ago #

    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.

  8. keesiemeijer
    moderator
    Posted 1 year ago #

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

  9. henballs
    Member
    Posted 1 year ago #

    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'); ?>
  10. keesiemeijer
    moderator
    Posted 1 year ago #

  11. henballs
    Member
    Posted 1 year ago #

    Hey it worked thanks so much for the help!

  12. keesiemeijer
    moderator
    Posted 1 year ago #

    You're welcome. I'm glad you've got it resolved :-)

Topic Closed

This topic has been closed to new replies.

About this Topic