0

I'm using the following code to display posts on my category page but would like to carry the same format through on to the second page of the category as at the moment it moves to the second page but doesn't show the older posts.

       <?php query_posts('showposts=3&cat=1461');
            while (have_posts()) : the_post();
            echo "<div class=column-post>";
            echo "<div class=category-thumb><a href=";
            echo get_permalink();
            echo ">";
            the_post_thumbnail(array (185,152));
            echo "</a></div>";
            echo "<div class=category-title><a href=";
            echo get_permalink();
            echo ">";
            the_title(); 
            echo "</a></div>";
            echo "<div class=category-desc>";
            the_excerpt();
            echo "</div>";
            echo "<div class=category-more><a href=";
            echo get_permalink();
            echo ">";
            echo "<img src=";
            bloginfo('template_directory');
            echo "/images/more.png>";
            echo "</a></div>";
            echo "</div>";
            endwhile;?>  </div>
  <div class="divider"></div>
  <div class="3-column-holder">
    <?php query_posts('showposts=3&offset=3&cat=1461');
            while (have_posts()) : the_post();
            echo "<div class=column-post>";
            echo "<div class=category-thumb><a href=";
            echo get_permalink();
            echo ">";
            the_post_thumbnail(array (185,152));
            echo "</a></div>";
            echo "<div class=category-title><a href=";
            echo get_permalink();
            echo ">";
            the_title(); 
            echo "</a></div>";
            echo "<div class=category-desc>";
            the_excerpt();
            echo "</div>";
            echo "<div class=category-more><a href=";
            echo get_permalink();
            echo ">";
            echo "<img src=";
            bloginfo('template_directory');
            echo "/images/more.png>";
            echo "</a></div>";
            echo "</div>";
            endwhile;?>
            </div>  <div class="divider"></div>
1

First make sure you've set your posts per page to 6 in the Reading settings - as I can see you're displaying 2 columns of 3 posts. Then you need to add the page variable to the query_posts attributes, by adding this before you query posts:

$paged = (get_query_var('page')) ? get_query_var('page') : 1;

and then changing the query_posts function calls to:

query_posts('showposts=3&cat=1461&paged='.$paged);

and

query_posts('showposts=3&offset=3&cat=1461&paged='.$paged);

You'll also want to cheange you links to the previous and next pages by using something like the next_posts and prev_posts tags or you can simply make it yourself by adding /page/2 (for example) to the end of the category permalink - if you're using pretty URLs of course.

It would probably be a good idea to check that you've got more than 3 posts to display before running the query for the second column too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.