2010-10-09 62 views

回答

3

它看起來像該鏈接有(幾乎)所有你需要的信息。

「較舊」基本上是「下一頁」,因此您在渲染器中覆蓋了next_page方法。 「最舊」是「最後一頁」;您需要添加一個方法,然後確保它包含在由pagination方法返回的數組中(will_paginate中構建的total_pages方法將在此處有所幫助)。

然後做相反的更新/最新。

看看link_renderer.rblink_renderer_base.rb文件。他們有你將被壓倒一切的方法。

我寫了一個自定義的will_paginate 3渲染器來模擬GitHub/Twitter風格的「更多」分頁。我註釋了下面的代碼。它不會讓你準確地到達需要去的地方,但這是一個開始。

module TwitterPagination 
    class LinkRenderer < WillPaginate::ViewHelpers::LinkRenderer 
    protected 

    # Tells WP how to render the "Next Page" link 
    def next_page 
     # The only difference from the default here is we renamed the link to "More" 
     # and added a custom class, twitter_pagination 
     previous_or_next_page(@collection.next_page, "More", 'twitter_pagination') if @collection.next_page 
    end 

    # Remove all links except our :next_page 
    def pagination 
     [ :next_page ] 
    end 
    end 
end 

爲了做到這一點,我需要知道的一切都可以通過閱讀上面鏈接的兩個源文件來解決。

這真的讓我感到驚訝,這是多麼容易; will_paginate的最新設計在這方面非常出色。

+0

謝謝,這很酷。但我仍然沒有遵循如何使它有條件(只有顯示更多,如果它是活動的)...另外,如何讓記錄查看&計數顯示在鏈接之前(25406的1 - 100) – AnApprentice 2010-10-09 18:30:06

+1

請注意'if @ 「collection.next_page」條件 - 如果實際上有下一頁,它只顯示「更多」。至於編號的項目,這有點複雜。查看[collection.rb]文件(http://github.com/mislav/will_paginate/blob/v3.0.pre2/lib/will_paginate/collection.rb)。它基本上是一個帶有額外方法的數組,因此您可以調用'@ collection.size'來知道此組中的項目數量;乘以'current_page'獲得開始,將組中的項目數加到開始以獲得最大邊界,等等。 – 2010-10-09 18:38:22

+0

明白了 - 謝謝! – AnApprentice 2010-10-10 03:18:13

0

嘗試像

<%= will_paginate @items, :class => 'apple_pagination' %> 

類也可以digg_pagination,.flickr_pagination。

在此之前,您需要download並將pagination.css複製到您的公共/樣式表中。