问题
I know this must be REALLY simple but after looking around I cannot find the answer.
I'm using the will_paginate plugin and I like to have a simple "next page" link instead of the whole will_paginate link collection.
How can I do this?
Thanks!
回答1:
This will give you just a simple next button to work with.
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, "Next", 'twitter_pagination') if @collection.next_page
end
# Remove all links except our :next_page
def pagination
[ :next_page ]
end
Let us know how you get on. Here is a great Blog Posts you should read as well. Let us know how you get on. All the best.
回答2:
It actually is a little more involved than you'd think to do it how some might call the "Rails Way". http://thewebfellas.com/blog/2008/8/3/roll-your-own-pagination-links-with-will_paginate
But you can also just make a helper and use the methods current_page
and total_pages
. So something like:
<% if @post.current_page < @post.total_pages %>
<%= link_to "Next", "#{posts_path(@post)}?page=#{@post.current_page+1}" %>
<% end %>
回答3:
Using will_paginate v3 on Rails v4:
<%= will_paginate @posts, :page_links=>false %>
来源:https://stackoverflow.com/questions/6121448/will-paginate-how-to-build-a-next-page-link