2010-04-06 90 views
2

我有一個從帖子中拉出許多項目的頁面。WordPress的:幫助posts_nav_link()

我將它設置爲一次只顯示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 } } 

回答

1

你手動調用query_posts(),這將改寫有關獲取該WordPress的嘗試帖子發送自身的變量。如果你想保留查詢字符串,它已經發送,您應該串聯到它,而不是取代它的:

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

或者,如果你只是想包括「頁面」變量,包括它$paged

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

我只是想...我認爲這是CLO ser但它仍然不起作用。也許我需要設置偏移...但不知道如何去做呢? – redconservatory 2010-04-06 20:58:45

+0

嗯,'$ paged'應該代表偏移量。例如,如果您在第4頁上,'$ paged'的值將是4.它應該與'posts_per_page'結合使用來確定偏移量。你現在得到什麼,哪些職位? – 2010-04-06 21:06:57

2

基於上面的幫助下,我纔剛剛得到它與這個工作:

<?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()) : ?>