views:

34

answers:

2

I have a page with many items pulled from posts.

I have it set up to only display 10 posts at a time, but my previous/next button isn't actually displaying the next or previous posts - it justs keeps displaying the same posts.

Here's the function I wrote:

  function add_shop() { 
    if (is_page('shop') || is_page('7')) { ?>
  <div id="content">
    <div class="post_box">
      <div id="column_1">
        <div id="shop_wrapper">
          <?php query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10');

if (have_posts()) : ?>
          <?php while (have_posts()) : the_post(); ?>
          <div class="shop_item"> <a href="<?php getCustomField('link_to_project_page'); ?>"><img src="<?php getCustomField('shop_thumbnail_image'); ?>" alt='photo of <?php getCustomField('title'); ?>' class="shop_thumb" /></a>
            <div class="shop_content">
              <h4><a href="<?php getCustomField('link_to_project_page'); ?>">
                <?php getCustomField('title'); ?>
                </a></h4>
              <?php getCustomField('duration'); ?>
              <?php getCustomField('paypal_code'); ?>
            </div>
          </div>
          <?php endwhile; ?>
        </div>
        <?php posts_nav_link(); ?>
      </div>
      <?php else : ?>
      <h2>Not Found</h2>
      <p>Sorry, but you are looking for something that isn't here.</p>
      <?php include (TEMPLATEPATH . "/searchform.php"); ?>
      <?php endif; ?>
    </div>
  </div>
  <div id="sidebars">
    <div id="sidebar_1" class="sidebar">
      <ul class="sidebar_list">
        <li class="widget">
          <div class="widget_box">
            <?php dynamic_sidebar(5); ?>
          </div>
        </li>
      </ul>
    </div>
  </div>
  <?php }   }
A: 

You're manually calling query_posts(), which will overwrite any variables related to fetching posts that wordpress tries to send itself. If you want to keep the query string that it's already sending, you should concatenate to it instead of replacing it:

query_posts($query_string.'&tag=shop&orderby=title&order=ASC&posts_per_page=10');

Alternatively, if you only want to include the "page" variable, include it with $paged:

query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10&paged='.$paged);
Chad Birch
I just tried that...I think it's closer but it's still not working. Maybe I need to set the offset...but not sure how to go about that?
redconservatory
Hmm, `$paged` should represent the offset. For example if you're on page 4, the value of `$paged` will be 4. It should use this in combination with `posts_per_page` to determine the offset. What are you getting now, which posts?
Chad Birch
A: 

Based on the above help, I just just got it working with this:

 <?php $page  = (get_query_var('paged')) ? get_query_var('paged') : 1;
          if ($page == 1) {
                query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10&paged=$page');
        } else {
             $numposts  = get_option('posts_per_page');

             // work out offset
             $offset = (($page -1) * $numposts); // i.e. page 2 - 1 = 1 * 10 (10 for the number of posts)

             query_posts("tag=shop&orderby=title&order=ASC&offset=$offset&paged=$page&showposts=$numposts");
            }



if (have_posts()) : ?>
redconservatory