The Ghost Themes Developer Hub

Welcome to the Ghost Themes developer hub. You'll find comprehensive guides and documentation to help you start working with Ghost Themes as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

prev_post & next_post

{{prev_post}} & {{next_post}} Helpers - Fetch the next or previous post from the current post

Usage: {{#prev_post}}{{title}}{{/prev_post}} - {{#next_post}}{{title}}{{/next_post}}

Types
Parameters
Attributes

n/a

n/a

Description

When in the scope of a post, you can call the next or previous post helper, which performs a query against the API to fetch the next or previous post in accordance with the chronological order of the blog.

Inside of the opening and closing tags of the {{#next_post}}{{/next_post}} or {{#prev_post}}{{/prev-post}} helper, the normal helpers for outputting posts will work, but will output the details of the post that was fetched from the API, rather than the original post.

{{#post}}
	<h2>{{title}}</h2>
	<div class="{{post_class}}">
		{{content}}
	</div>

	{{#prev_post}}
		<a href="{{url}}">{{title}}</a>
	{{/prev_post}}

	{{#next_post}}
		<a href="{{url}}">{{title}}</a>
	{{/next_post}}
{{/post}}

Like all block helpers, next_post and prev_post support adding an {{else}} block or using ^ instead of # for negation - this means that the {{#next_post}} and {{else}} blocks are reversed if you use {{^next_post}} and {{else}} instead. This can be used to output content if there is no next or previous post available.

{{#next_post}}
	<p><a href="{{url}}">{{title}}</a></p>
{{else}}
	<p>No more posts!</p>
{{/next_post}}

Note: The next and previous post helpers cannot be nested inside each other. This is because they are performing a query, and we currently cannot support nesting queries inside each other.

You can do more than one query on a page though, so you can use both {{#next_post}} and {{#prev_post}} in the same template, or call either of them multiple times.

prev_post & next_post

{{prev_post}} & {{next_post}} Helpers - Fetch the next or previous post from the current post