Forum

Thread tagged as: Question, Blog

Next/Prev Post Pagination on individual post page.

I wanted to add this feature to my individual post pages so that users can click back and forth between the prev/next posts . On the siteInspire individual post pages it has what I'd like to have - https://www.siteinspire.com/websites/4968-the-avery-review

Is there a way to do this?

David Springate

David Springate 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes., by filtering with perch_blog_custom().

The previous post is the first post with a date less than the current post's date.

The next post is the first post with a date greater than the current post's date.

Cool thanks Drew I will try to add that now.

David did you manage to do this? I need to do the same from each news post have a next/prev link

I have the following in my post.php page;

<?php
            perch_blog_custom(array(
                'count' => 1,
                'template' => 'post.html',
                'filter' => 'postSlug',
                'match' => 'eq',
                'value' => perch_get('s'),
?>

and the following in my post.html template page.

<perch:if exists="paging">
    <div class="pagination pagination--news">
        <perch:if exists="not_first_page">
            <a href="<perch:blog id="prev_url" encode="false" />" class="pagination__link pagination__link--prev" rel="prev">
                <svg class="icon" viewBox="0 0 25 25"><use xlink:href="#icon-arrow-circle"></use></svg>
                Previous Article
            </a>
        </perch:if>
        <perch:if exists="not_last_page">
            <a href="<perch:blog id="next_url" encode="false" />" class="pagination__link pagination__link--next" rel="next">
                Next Article
                <svg class="icon" viewBox="0 0 25 25"><use xlink:href="#icon-arrow-circle"></use></svg>
            </a>
        </perch:if>
    </div>
</perch:if>

But I am not getting any pagination links? The article is outputting onto the screen though.

I also have two empty fields in my post page in the admin. So perhaps I need suppress on the next/prev ID fields. But thought perhaps not as they were part of the core system/functionality?

Drew can you see where I am going wrong at all? Been a few months since I did a Perch site and a little out of touch.

Thanks.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Terry - please start your own thread if you have an issue. We can't keep track of multiple people in one thread.