Getting the last X number of pages in pagination
As I already wrote in my comment 3 days ago something like this should work

{% paginate craft.entries.section('mySection').limit(10) as pageInfo, pageEntries %}

{% for page, url in pageInfo.getPrevUrls(3) %}
    &lt;a href="{{ url }}"&gt;{{ page }}&lt;/a&gt;
{% endfor %}

&lt;span class="current"&gt;{{ pageInfo.currentPage }}&lt;/span&gt;

{% for page, url in pageInfo.getNextUrls(3) %}
    &lt;a href="{{ url }}"&gt;{{ page }}&lt;/a&gt;
{% endfor %}

{% if pageInfo.totalPages - pageInfo.currentPage &gt; 3 %}
    &lt;span&gt;...&lt;/span&gt;

    &lt;a href="{{ pageInfo.lastUrl }}"&gt;{{pageInfo.totalPages}}&lt;/a&gt;
{% endif %}


[EDIT]: In the above script you will come across situations where the gap sometimes occurs between consecutive numbers, which can look silly.





To fix this you can add a little extra logic to it:

{% set amountVisible = amountVisible|default(2) %}
{% if pageInfo.currentPage &gt; amountVisible + 1 %}
    &lt;a href="{{ pageInfo.firstUrl }}"&gt;1&lt;/a&gt;

    {% if pageInfo.currentPage == amountVisible + 3 %}
        &lt;a href="{{ pageInfo.getPageUrl(2) }}"&gt;2&lt;/a&gt;
    {% elseif pageInfo.currentPage &gt; amountVisible + 3 %}
        &lt;span&gt;...&lt;/span&gt;
    {% endif %}
{% endif %}

{% for page, url in pageInfo.getPrevUrls(amountVisible) %}
    &lt;a href="{{ url }}"&gt;{{ page }}&lt;/a&gt;
{% endfor %}

&lt;span class="current"&gt;{{ pageInfo.currentPage }}&lt;/span&gt;

{% for page, url in pageInfo.getNextUrls(amountVisible) %}
    &lt;a href="{{ url }}"&gt;{{ page }}&lt;/a&gt;
{% endfor %}

{% if pageInfo.totalPages - pageInfo.currentPage &gt; amountVisible %}
    {% if pageInfo.totalPages - pageInfo.currentPage == amountVisible + 2 %}
        &lt;a href="{{ pageInfo.getPageUrl(pageInfo.totalPages - 1) }}"&gt;{{pageInfo.totalPages - 1}}&lt;/a&gt;
    {% elseif pageInfo.totalPages - pageInfo.currentPage &gt; amountVisible + 1 %}
        &lt;span&gt;...&lt;/span&gt;
    {% endif %}

    &lt;a href="{{ pageInfo.lastUrl }}"&gt;{{pageInfo.totalPages}}&lt;/a&gt;
{% endif %}


Now this added logic will do two things:


If there is no gap, it won't render a thing.
If the gap only amounts to one page it will render a page number instead.


This results in the following:



As an added bonus: if you add the amountVisible variable on top with a default value you can put this in a twig partial which you can then easily implement on the paged view like so:

{% include 'partials/pager' with { pageInfo: pageInfo, amountVisible: 3 } %}

(Note that passing pageInfo explicitly is not required, but I do it for the sake of completeness and to prevent accidental cleanups of "unused" vars.)