2011-11-19 83 views
0

我正在爲我的wordpress啓用site.being創建一個相關的文章後功能,它是面向一些問題的PHP和WordPress新手。 雖然我可以用wordpress的功能來顯示作者的相關帖子,但由於網站是託管的作家誰沒有任何配置文件的文章,並且有很多這樣的作者,所以當爲作者創建一個新的帖子時,我們傾向於將自定義字段保存爲author_email。 所以在此基礎上,我們要顯示所有文章被髮表,particual author.i使用get_posts嘗試()方法getPost()方法和分頁

<?php 
     $args = array('meta_key' => 'author_email', 'meta_value' => '[email protected]'); 
     $authorposts=get_posts($args); ?> 
    <div id="content"> 
    <span class="breadcrumbs"><a href="<?php echo get_option('home'); ?>/">Home</a> &raquo; <?php the_category(', ') ?></span> 
    <?php if (count($authorposts) > 0) { 
    foreach ($authorposts as $post): setup_postdata($post)   ?> 
    <div id="headline_author"> 
     /* 
      showing post tilte with image and some part of it 
     */ 
     <div class="clearfloat"></div> 
    </div> 
    <?php endforeach; ?> 
    <div class="post-nav"> 
       <div class="previous"><?php previous_posts_link('&lsaquo; Previous Page') ?></div> 
       <div class="next"><?php next_posts_link('Next Page &rsaquo;') ?></div> 
    </div> 
    <?php 
        } else { 
         echo '<p>No articles by this user</p>'; 
        }  
        ?> 
</div> 

它顯示前5個結果,併到下一個頁面的鏈接,但是當我點擊下一頁顯示它已經到了第二頁,因爲它在URL上也是可見的,但它顯示了它在第一頁中顯示的結果。 我是一個想法,我已經寫在同一頁面上的查詢從頭再次執行,但不知道如何解決它。 因爲我使用cutom字段獲取帖子我可以使用簡單的查詢來獲取帖子基於限制或offse等

任何人都可以幫助我解決這些事情,或可以指出我要正確做到這一點

在此先感謝

回答

0

我不是wordpress/php專家剛剛開始瞭解它。看起來你沒有設置它可以跟蹤頁碼的分頁全局變量。

你需要做這樣的事情。

$post_per_page = get_option('posts_per_page'); 
      if (!is_paged()) { 
      $custom_offset = 0; 
      } else { 
      $custom_offset = $post_per_page*($paged-1); 
      } 
      $args = array('meta_key' => 'author_email', 'meta_value' => [email protected]' ,'numberposts' => $post_per_page,'offset' => $custom_offset);