WordPress.org

Ready to get started?Download WordPress

Forums

next_posts_link() links to the same posts, not to the new ones. (1 post)

  1. patpatpat
    Member
    Posted 11 months ago #

    Hi.
    Thanks to your support, and the codex, I came to this

    <?php
    /*
    Template Name: index
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="inhalt" class="text_single">
    
    <?php
    // set the "paged" parameter (use 'page' if the query is on a static front page)
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 0;
    
    // the query
    $wp_query = new WP_Query( 'cat=3,9,10,23&paged=' . $paged );
    ?>
    
    <?php if ( $wp_query->have_posts() ) : ?>
    
    <?php
    // the loop
    while ( $wp_query->have_posts() ) : $wp_query->the_post();
    ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
    
    <?php
    // usage with max_num_pages
    next_posts_link( 'Older Entries', $wp_query->max_num_pages );
    previous_posts_link( 'Newer Entries' );
    ?>
    
    <?php
    // clean up after our query
    wp_reset_postdata(); ?>
    <?php else:  ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
    
    </div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    And the posts are shown. But if click on the "Older Entries" link, the URL is .../page/2/ and the posts are just the same.
    I just found the code here http://codex.wordpress.org/Function_Reference/next_posts_link and just put it between the header and footer stuff. So I'm wondering why it's not working. I read it's better to change $the_query to $wp_query, so I did that. But it didn't change anything. I'd greatly appreciate if someone could give me a hint.

Reply

You must log in to post.

About this Topic