代码之家  ›  专栏  ›  技术社区  ›  redconservatory

文章帮助

  •  2
  • redconservatory  · 技术社区  · 16 年前

    我有一个网页,有许多项目从帖子。

    我把它设置为一次只显示10个帖子,但是我的“上一个/下一个”按钮实际上并没有显示下一个或前一个帖子,它只是一直显示相同的帖子。

    下面是我写的函数:

      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 }   }
    
    2 回复  |  直到 16 年前
        1
  •  2
  •   redconservatory    16 年前

    基于以上的帮助,我 只是

     <?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()) : ?>
    
        2
  •  1
  •   Chad Birch    16 年前

    你在手动呼叫 query_posts()

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

    或者,如果只想包含“page”变量,请将其包含在 $paged :

    query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10&paged='.$paged);
    
    推荐文章