Forums

[resolved] Same posts on all pages issue (8 posts)

  1. Bruce Alrighty
    Member
    Posted 3 years ago #

    I have a loop in which I want to display 1 post on the page and then have next and previous links to the next page of 1 post and so on.

    For some reason the post on the 1st page is the same as the one on the 2nd page. So the 2nd post does not appear. Can anyone explain why?

    Below is my loop:

    <ul class="gallery clearfix">
    
    <?php query_posts('category_name=events&posts_per_page=1'); ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); $do_not_duplicate = $post->ID; ?>
    
        <?php the_content(); ?>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
    <?php posts_nav_link(); ?>
  2. Chris_K
    Member
    Posted 3 years ago #

    what happens if you set your Permalinks back to default?

  3. Bruce Alrighty
    Member
    Posted 3 years ago #

    I reset the permalinks and no change.

  4. Bruce Alrighty
    Member
    Posted 3 years ago #

    You can see a demo here http://cmphotographer.com.au/events/

  5. Chris_K
    Member
    Posted 3 years ago #

    So backing up a step, why not use a "normal" Loop? (see The_Loop for docs) Then just set your options to show one page at a time?

  6. Bruce Alrighty
    Member
    Posted 3 years ago #

    I changed the settings in the admin to 1 and removed the query, but now no posts are displayed.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php the_content(); ?>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
  7. Otto
    Tech Ninja
    Posted 3 years ago #

    Instead of this:

    <?php query_posts('category_name=events&posts_per_page=1'); ?>

    Use this:

    <?php query_posts($query_string.'&category_name=events&posts_per_page=1'); ?>

  8. Bruce Alrighty
    Member
    Posted 3 years ago #

    @Otto42 I tried it and still no posts are displayed.

Topic Closed

This topic has been closed to new replies.

About this Topic