will_paginate: how to build a “next page” link?

青春壹個敷衍的年華 提交于 2019-12-13 17:48:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!