2011-05-03 134 views
3

好吧,我一直在盯着這個近一個小時,並且無法啓動它。我使用的是WordPress,我在系統中有12篇文章。在管理員中,我將其設置爲每頁顯示5篇文章。在我的主題中,我試圖在底部顯示分頁(prev,1,2,3,4,next)。我發現paginate_links()函數在WordPress的指南,並沒有打印任何東西,出來...任何幫助表示讚賞:在WordPress主題中的分頁帖子

<?php get_header(); ?> 
<div class="middle-container"> 
    <div class="middle"> 
     <div class="column main"> 
      <div class="latest"> 
      <?php 
      $i = 0; 
      if (have_posts()): 
       while (have_posts() && $i < 1): 
        the_post(); 
        ?> 
        <div class="image"><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a> 
        </div> 
        <div class="content"> 
        <h1><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1> 
        <span class="date"><?php the_time('F jS, Y') ?></span> 
        <?php 
        the_excerpt(); 
        ?> 
        </div> 
        <?php 
        $i++; 
       endwhile; 
      endif; 
      ?> 
      </div> 
      <ul class="posts"> 
      <?php 
      $i = 0; 
      if (have_posts()): 
       while (have_posts() && $i < 4): 
        the_post(); 
        ?> 
        <li> 
        <h2><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 
        <span class="date"><?php the_time('F jS, Y') ?></span> 
        <?php 
        the_excerpt(); 
        ?> 
        </li> 
        <?php 
        $i++; 
       endwhile; 
      endif; 
      ?> 
      </ul> 
      <?php 
      echo paginate_links(); 
      ?> 
     </div> 
     <div class="column sidebar"></div> 
    </div> 
</div> 
<?php get_footer(); ?> 

這個多一點背景:第一個while循環中的代碼抓起首先在列表中發佈並顯示在它自己的特殊塊中。第二個while循環抓取剩下的4個帖子。這兩個while循環都可以很好地工作。分頁只是不打印出來。

+0

這個問題應該被移植到http://wordpress.stackexchange.com – GavinR 2011-05-03 21:10:56

回答

1

似乎Wordpress paginate_links函數需要一個參數。

我會嘗試他們的默認示例,看看它是否工作。

<?php 
paginate_links(array(
    'base'   => '%_%', 
    'format'  => '?page=%#%', 
    'total'  => 1, 
    'current'  => 0, 
    'show_all'  => False, 
    'end_size'  => 1, 
    'mid_size'  => 2, 
    'prev_next' => True, 
    'prev_text' => __('&laquo; Previous'), 
    'next_text' => __('Next &raquo;'), 
    'type'   => 'plain', 
    'add_args'  => False, 
    'add_fragment' => )); 
?> 
+0

我今天會給你一個鏡頭,讓你知道它是怎麼回事! – Avisra 2011-05-03 11:54:45

+0

還是什麼都沒有......我甚至嘗試在前面添加一個「回聲」。它不打印任何東西。 – Avisra 2011-05-03 13:40:05

0

找到了我的解決方案的答案。如果您將「總數」保留爲1,則該函數不會執行任何操作。您必須將頁面數量放在「總計」參數中。我會認爲,WordPress會足夠聰明,使該功能抓住從收集的帖子數量...

反正 - 任何人都在尋找分頁功能,不需要很多的自定義代碼(如paginate_links會),看看這個: http://wordpress.org/extend/plugins/wp-paginate/

似乎工作得很好。