Complete and flexible blogging platform for ProcessWire

Render Next/Previous Posts

The method renderNextPrevPosts() is a small utility method that renders navigation links that help navigate to the next and previous Blog Posts. if there is no next or previous Post, nothing is output respectively. 

<?php
 /**
 * Render previous and next posts links.
 *
 * As seen on the frontend page: /blog/post/ = where 'post' = name of the post
 *
 * @access public
 * @param Page $page
 * @return string $out
 *
 */
 public function renderNextPrevPosts($page)

The method accepts one argument, $page, which has to be a ProcessWire Page. In the demo template files that ships with Blog, the method can be seen in action in 'blog-post.php', i.e. when viewing an individual Post page. The code below shows how to use the method.

<?php
//first we call MarkupBlog
$blog = $modules->get('MarkupBlog');

//render next/previous links
echo $blog->renderNextPrevPosts($page);

As shown in the HTML output below, the next/previous links will be the respective Posts' titles.

renderNextPrevPosts() HTML output

<div class="next-prev-posts">
 <p class="prev-post"><span>&lt;</span><a href="/pwtests/blog/posts/imagine/">Imagine</a></p>
 <p class="next-post"><a href="/pwtests/blog/posts/another-place/">Another Place</a><span>&gt;</span></p>
</div>

renderNextPrevPosts() CSS

The CSS classes from the rendered markup is shown below.

div.next-prev-posts {}
p.prev-post {}
p.next-post {}

Summary

We have looked at renderNextPrevPosts($page), a utility method that is useful on individual Blog Post pages. It outputs a link to the next and previous Posts as applicable, hence facilitating navigation of your Blog's Posts.