[resolved] Problem with 'Older Entries" link. (4 posts)

  1. milktheman
    Posted 3 years ago #

    I'm having what seems like a fairly common problem, however I can't resolve my issue with the advise in other resolved threads.

    I have a blog-homepage template that is set to display 5 posts. When I click the 'older entries' link (or 'newer entries') the returned page/2, page/3, etc, displays the same 5 most recent posts.

    Here is everything between my div that holds the post's content and the footer:

    <?php query_posts("posts_per_page=5"); ?>
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    	<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    	<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    	<div class="entry">
    	<?php the_content(); ?>
    	<div class="postmetadata">
    	<?php comments_popup_link('No Comments »', '1 Comment »', '%        Comments »'); ?>
    	<?php endwhile; ?>
    	<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
    	<?php else : ?>
    	<h2>Not Found</h2>
    	<?php endif; ?>

    I have also tried disabling all plug-ins to test for compatibility.

    Any hints would be fantastic. Thank you!

  2. vtxyzzy
    Posted 3 years ago #

    You must include the 'paged' argument to query_posts in order for pagination to work. Try changing this:

    <?php query_posts("posts_per_page=5"); ?>

    to this:

    <?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    query_posts("posts_per_page=5&paged=$paged"); ?>
  3. milktheman
    Posted 3 years ago #

    THANKS! That'll do it. I appreciate the help. Now I'm going to look up why that works so I don't forget to do that in the future.

  4. vtxyzzy
    Posted 3 years ago #

    If your problem has been solved, please use the dropdown on the right to mark this topic 'Resolved' so that anyone else with this question can see that there is a solution.

Topic Closed

This topic has been closed to new replies.

About this Topic