<p>Pagination is for breaking up a list of entries into different pages. p3 means page 3 of entries.</p>

<p>What you're looking for is the ability to link to the next/previous entry. If you are ordering your entries like a blog, by post date, newest first you can create the links like this. On your single entry template:</p>

<pre><code>{% set nextEntry = craft.entries.section('posts')
    .postDate('&gt;= ' ~ entry.postDate.timestamp)
    .order('postDate asc')
    .id('not ' ~ entry.id)
    .one() %}

{% if nextEntry %}
    &lt;a href="{{ nextEntry.url }}"&gt;Next Post&lt;/a&gt;
{% endif %}

{% set previousEntry = craft.entries.section('news')
     .postDate('&lt;= ' ~ entry.postDate.timestamp)
     .order('postDate desc')
     .id('not ' ~ entry.id)
     .one() %}

{% if previousEntry %}
    &lt;a href="{{ previousEntry.url }}"&gt;Previous Post&lt;/a&gt;
{% endif %}
</code></pre>

<p><code>entry</code> is the current entry you're viewing. If you're ordering the entries in a different way you can adjust the queries. <a href="https://craftcms.stackexchange.com/a/27272/50">This answer</a> goes into more detail, including how to change this if you're ordering by title.</p>

<p>If you have your entries in a structure section you can do this:</p>

<pre><code>{% if entry.getNextSibling() %}
    &lt;a href="{{ entry.getNextSibling().url }}"&gt;Previous Post&lt;/a&gt;
{% endif %}

{% if entry.getPrevSibling() %}
    &lt;a href="{{ entry.getPrevSibling().url }}"&gt;Previous Post&lt;/a&gt;
{% endif %}
</code></pre>

CC BY-SA 4.0
2019-07-05T17:35:41.970Z
2019-07-05T17:58:39.167Z
2019-07-05T17:58:39.167Z
Simon Kuran
<p>I've setup a 'posts' section with a collection of posts. I'm trying to add pagination to the individual post entry.</p>

<p>I've copied the pagination code from the Craft CMS documentation but I'm having issues with the slug.</p>

<p>The problem is my slugs are like: posts/post-1, posts/post-2, posts/post-3 etc.</p>

<p>And when you click on the 'previous' or 'next' post the slug is like 'post-3/p3' which the 'p3' on the end.</p>

<p>How do I convert that to my normal post slug of just 'post-3'.</p>

<p>Thanks!</p>

<p>Here is my code:</p>

<pre><code>{% set query = craft.entries()
        .section('posts')
        .limit(1) %}

{% paginate query as pageInfo, pageEntries %}

&lt;div class="pagination"&gt;
    &lt;a class="pagination__group" href="#"&gt;
        {% if pageInfo.prevUrl %}
            &lt;a href="{{ pageInfo.prevUrl }}"&gt;Previous Page&lt;/a&gt;
        {% endif %}
    &lt;/a&gt;
    &lt;a class="pagination__group" href="#"&gt;
        {% if pageInfo.nextUrl %}
            &lt;a href="{{ pageInfo.nextUrl }}"&gt;Next Page&lt;/a&gt;
        {% endif %}
    &lt;/a&gt;
&lt;/div&gt;
</code></pre>

<craft3><pagination><craft2>
Pagination Slug Issue
# Pagination Slug Issue

(Asked by: username_0 on 2019-07-05)

I've setup a 'posts' section with a collection of posts. I'm trying to add pagination to the individual post entry.
I've copied the pagination code from the Craft CMS documentation but I'm having issues with the slug.
The problem is my slugs are like: posts/post-1, posts/post-2, posts/post-3 etc.
And when you click on the 'previous' or 'next' post the slug is like 'post-3/p3' which the 'p3' on the end.
How do I convert that to my normal post slug of just 'post-3'.
Thanks!
Here is my code:
{% set query = craft.entries()
        .section('posts')
        .limit(1) %}

{% paginate query as pageInfo, pageEntries %}


    
        {% if pageInfo.prevUrl %}
            Previous Page
        {% endif %}
    
    
        {% if pageInfo.nextUrl %}
            Next Page
        {% endif %}

**Tags:** craft3, pagination, craft2


---

## 1 answers

### Answer by username_1 on 2019-07-05. Score: 2 | Accepted answer

Pagination is for breaking up a list of entries into different pages. p3 means page 3 of entries.
What you're looking for is the ability to link to the next/previous entry. If you are ordering your entries like a blog, by post date, newest first you can create the links like this. On your single entry template:
{% set nextEntry = craft.entries.section('posts')
    .postDate('>= ' ~ entry.postDate.timestamp)
    .order('postDate asc')
    .id('not ' ~ entry.id)
    .one() %}

{% if nextEntry %}
    Next Post
{% endif %}

{% set previousEntry = craft.entries.section('news')
     .postDate('<= ' ~ entry.postDate.timestamp)
     .order('postDate desc')
     .id('not ' ~ entry.id)
     .one() %}

{% if previousEntry %}
    Previous Post
{% endif %}

entry is the current entry you're viewing. If you're ordering the entries in a different way you can adjust the queries. This answer goes into more detail, including how to change this if you're ordering by title.
If you have your entries in a structure section you can do this:
{% if entry.getNextSibling() %}
    Previous Post
{% endif %}

{% if entry.getPrevSibling() %}
    Previous Post
{% endif %}


---

