Support » Fixing WordPress » Pagination and query_posts

  • martiniboy

    (@martiniboy)


    I am having a problem with using query posts and the pagination system when I click page 2 etc. it refreshes page 1. Has anyone got any suggestions?
    Due to the design I am showing the full post and under that I have a second loop to show two of the excerpts with the paginator to show the rest of the posts
    Here is my code
    `<div id="newscontent">
    <?php query_posts('showposts=1'); ?>
    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <div class="date">Written by <span class="author"><?php the_author() ?></span> On <span class="author"><?php the_time('F jS, Y') ?></span> Posted in <?php the_category(', ') ?></div>
    <?php the_content('Read the rest of this entry »'); ?>
    <div class="clear"></div>
    </div><!--end of homecontent-->
    <?php endwhile; endif; ?>
    </div><!--end of maincol-->
    <div id="maincolbot"></div>
    <div id="excerptboxes">

    <?php if (have_posts()) : ?>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("posts_per_page=2&offset=1&paged=$paged"); ?>

    <?php while (have_posts()) : the_post(); ?>
    <div class="excerpts">
    <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    <p><?php excerpt('40'); ?> </p>
    <div class="excerpt_bottom"></div>
    </div><!--end of excerpts-->
    <?php endwhile; ?>
    <div class="clear"></div>

    <div id="navigation">
    <?php if(function_exists('wp_page_numbers')) : wp_page_numbers(); endif; ?>
    </div>

    <?php endif; ?>`

Viewing 4 replies - 1 through 4 (of 4 total)
  • chinmoy29

    (@chinmoy)

    <div id="newscontent">
    <?php query_posts('showposts=1'); ?>
    <?php if (have_posts()) : ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <div class="date">Written by <span class="author"><?php the_author() ?></span> On <span class="author"><?php the_time('F jS, Y') ?></span> Posted in <?php the_category(', ') ?></div>
    <?php the_content('Read the rest of this entry ยป'); ?>
    <div class="clear"></div>
    </div><!--end of homecontent-->
    <?php endwhile; endif; ?>
    </div><!--end of maincol-->
    <div id="maincolbot"></div>
    <div id="excerptboxes">
    
    <?php wp_reset_query(); if (have_posts()) : ?>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("posts_per_page=2&offset=1&paged=$paged"); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    <div class="excerpts">
    <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    <p><?php excerpt('40'); ?> </p>
    <div class="excerpt_bottom"></div>
    </div><!--end of excerpts-->
    <?php endwhile; ?>
    <div class="clear"></div>
    
    <div id="navigation">
    <?php if(function_exists('wp_page_numbers')) : wp_page_numbers(); endif; ?>
    </div>
    
    <?php endif; ?>

    Try once.

    martiniboy

    (@martiniboy)

    Thanks for your fast response unfortunately because we have reset the query after the main post at the top the subsequent excerpts are not being shown now.

    Thanks anyway

    chinmoy29

    (@chinmoy)

    remove wp_reset_query(); and modify the code with query_posts(“posts_per_page=2&offset=1&paged=”.$paged);

    martiniboy

    (@martiniboy)

    This changes the pages and shows the two excerpts but it shows the same posts on every page. I have just been reading that offset and pagination do not mix so looks like I am going to hack around with the functions.php!!

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pagination and query_posts’ is closed to new replies.