<p>You can detect if the requested page is greater than the total available pages for the current list of entries like so:</p>

<pre><code>{% paginate entries as entriesOnPage %}

    {% if craft.request.getPageNum() &gt; paginate.totalPages %}
        &lt;p&gt;No results&lt;/p&gt;
    {% else %}
        {% for entry in entriesOnPage %}
            ...
        {% endfor %}
    {% endif %}

{% endpaginate %}
</code></pre>

<p>Rather than displaying a message, you could also choose to put an <code>{% exit 404 %}</code> tag in there.</p>

CC BY-SA 3.0
2015-01-06T11:51:03.960Z
2015-01-06T11:51:03.960Z
Brandon Kelly
<p>I understand I can use a conditional to output a 'next page' link only when next pages exist, but I am finding a problem with direct URLs. </p>

<p>Let's say you have 20 entries and 10 per page. </p>

<p>The URL <strong>/news</strong> (or <strong>/news/p1</strong>) and <strong>/news/p2</strong> should work, but I would expect <strong>/news/p3</strong> to show no results or a message.</p>

<p>What I'm finding however is that <strong>/news/p3</strong> and beyond returns the last entry in the collection.</p>

<p>Here's the template code:</p>

<pre><code>{% paginate craft.entries.section(listingSection).order('postDate desc').limit(2) as entriesOnPage %}

    &lt;div class="ral-loading ral-hero-block ral-headline"&gt;Loading the latest content...&lt;/div&gt;

    &lt;div class="isotope js-isotope" &gt;

        {% for entry in entriesOnPage %}

            {% if entry.section.handle != 'tweet' %}

                {% switch entry.tileSize %}

                    {% case "Single" %}

                        {% include '_partials/_isotope_block_single.html' %}

                    {% case "Double Horizontal" %}

                        {% include '_partials/_isotope_block_horizontal.html' %}

                    {% case "Double Vertical" %}

                        {% include '_partials/_isotope_block_vertical.html' %}

                    {% case "Quadruple" %}

                        {% include '_partials/_isotope_block_big.html' %}

                    {% case "Quote" %}

                        {% include '_partials/_isotope_block_quote.html' %}

                {% endswitch %}

            {% else %}

                {% include '_partials/_isotope_block_tweet.html' %}

            {% endif %}

        {% endfor %}

    &lt;/div&gt;

    {% if paginate.nextUrl %}

        &lt;div class="ral-load-more-posts nav-previous"&gt;

            &lt;div class="container"&gt;

                &lt;a class="ral-load-more-posts-text" href="{{ paginate.nextUrl }}"&gt;Load more posts&lt;/a&gt;

            &lt;/div&gt;

        &lt;/div&gt;

    {% endif %}

{% endpaginate %}
</code></pre>

CC BY-SA 3.0
2015-01-05T16:29:39.437Z
Can you share your pagination template code?
Brad Bell
CC BY-SA 3.0
2015-01-05T16:31:12.863Z
I've edited the question to include the template code.
Russ Back
CC BY-SA 3.0
2015-01-05T18:12:42.087Z
Curious... what's the purpose of the `limit(2)` in the opening paginate block?  It [might not be doing](http://craftcms.stackexchange.com/a/4319/57) what you think it's doing.
Brad Bell
CC BY-SA 3.0
2015-01-05T19:57:56.603Z
I want to set a number of entries per page, in this case 2.
Russ Back
<entries><pagination>
Pagination returns a result after last page has been reached
# Pagination returns a result after last page has been reached

(Asked by: username_0 on 2015-01-05)

I understand I can use a conditional to output a 'next page' link only when next pages exist, but I am finding a problem with direct URLs. 
Let's say you have 20 entries and 10 per page. 
The URL /news (or /news/p1) and /news/p2 should work, but I would expect /news/p3 to show no results or a message.
What I'm finding however is that /news/p3 and beyond returns the last entry in the collection.
Here's the template code:
{% paginate craft.entries.section(listingSection).order('postDate desc').limit(2) as entriesOnPage %}

    Loading the latest content...

    

        {% for entry in entriesOnPage %}

            {% if entry.section.handle != 'tweet' %}

                {% switch entry.tileSize %}

                    {% case "Single" %}

                        {% include '_partials/_isotope_block_single.html' %}

                    {% case "Double Horizontal" %}

                        {% include '_partials/_isotope_block_horizontal.html' %}

                    {% case "Double Vertical" %}

                        {% include '_partials/_isotope_block_vertical.html' %}

                    {% case "Quadruple" %}

                        {% include '_partials/_isotope_block_big.html' %}

                    {% case "Quote" %}

                        {% include '_partials/_isotope_block_quote.html' %}

                {% endswitch %}

            {% else %}

                {% include '_partials/_isotope_block_tweet.html' %}

            {% endif %}

        {% endfor %}

    

    {% if paginate.nextUrl %}

        

            

                Load more posts

            

        

    {% endif %}

{% endpaginate %}

**Tags:** entries, pagination

> **Comments:**
> **username_1**: Can you share your pagination template code?  
> **username_0**: I've edited the question to include the template code.  
> **username_1**: Curious... what's the purpose of the `limit(2)` in the opening paginate block?  It [might not be doing](http://craftcms.stackexchange.com/a/4319/57) what you think it's doing.  
> **username_0**: I want to set a number of entries per page, in this case 2.  

---

## 1 answers

### Answer by username_2 on 2015-01-06. Score: 1 | Accepted answer

You can detect if the requested page is greater than the total available pages for the current list of entries like so:
{% paginate entries as entriesOnPage %}

    {% if craft.request.getPageNum() > paginate.totalPages %}
        No results
    {% else %}
        {% for entry in entriesOnPage %}
            ...
        {% endfor %}
    {% endif %}

{% endpaginate %}

Rather than displaying a message, you could also choose to put an {% exit 404 %} tag in there.


---

