看起来该链接具有(几乎)您需要的所有信息。
“旧”基本上是“下一页”,因此您next_page
在渲染器中覆盖该方法。“最旧”是“最后一页”;您需要添加一个方法,然后确保它包含在您的pagination
方法返回的数组中(total_pages
will_paginate 内置的方法将在此处提供帮助)。
然后对 Newer/Newest 执行相反的操作。
查看link_renderer.rb和link_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 的最新设计在这方面非常出色。