Question

Is there any way so that i can display only the current page link with << Previous link hidden when i am on first page and next >> link hidden when i am on last page.
It should be as follows

on first page : 1 | next >>

on last page(since having 4 pages) : << previous | 4

example of any center page : << previous | 3 | next >>

currently what i am getting is : << previous | 1 ... 4 | next >>

My code

<%= will_paginate @blogs, :class=>"pagination_links",:page_links => true, :next_label => "<span>|&nbsp</span>Next >>",:previous_label => "<< Previous<span>&nbsp|</span>",:inner_window   => 0, :outer_window => 0 %> 

Generated html is

<div class="pagination_links">
<span class="previous_page disabled">
<< Previous
<span> |</span>
</span>
<em class="current">1</em>
<span class="gap">…</span>
<a href="/blog?page=4">4</a>
<a class="next_page" href="/blog?page=2" rel="next">
<span>| </span>
Next >>
</a>
</div>

any solution for this?

Was it helpful?

Solution 2

I achieved this using css

   .current {
        display: inline-block;
        font-size: 12px;
        text-decoration: none;
        color: #000000;
    }
    .gap{
        display : none !important;
    }
    .pagination_links a{
        display:none;
    }
    .next_page,.previous_page{
        display:inline-block !important;
        color: #3343A0;
    }
    .pagination_links{
        text-align: center;
    }
    .previous_page.disabled, .next_page.disabled{
        display: none !important;
    }        
    .pagination_links a{
        text-decoration: none;
    }
    .pagination_links a:hover{
        text-decoration: underline;
    }
    .pagination_links span{
        text-decoration: none;
        display: inline-block;
        color: #000000;
    }

OTHER TIPS

Using the default API options this is not currently possible, but will_paginate allows you to make custom link renderers.

To do this add the renderer key to your will_paginate function and tell it what renderer to use.

 <%= will_paginate @pages, renderer: PaginationLinkRenderer, previous_label:"« Previous |", next_label:"| Next »" %>

and create a file either in helpers/ or lib/ called pagination_link_renderer.rb and add the following:

class PaginationLinkRenderer < WillPaginate::ActionView::LinkRenderer

  protected

  def page_number(page)
   if page == current_page
     page
   end
  end

  def previous_or_next_page(page, text, classname)
    if page
      link(text, page, class: classname)
    end
  end

end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top