Add previous/next links to post template
In case you want to add previous/next post links, add the following post query to your post template.
allWordpressPost {
edges {
next {
title
slug
}
previous {
title
slug
}
node {
id
}
}
}
Next, add the following to the render method of your Post Component class
render() {
const post = this.props.data.wordpressPost
const edges = this.props.data.allWordpressPost.edges.filter( (edge) =>
edge.node.id === post.id )
const next = edges ? edges[0].previous : ""
const prev = edges ? edges[0].next : ""
const Next = () => {
return next ? <div>Next: <Link to={next.slug}>{next.title}</Link></div> : ""
}
const Prev = () => {
return prev ? <div>Previous: <Link to={prev.slug}>{prev.title}</Link></div> : ""
}
...
<Next/>
<br />
<Prev/>
<br />
...
There should now be links to your previous and next post included in your post.
Next: Add author to copyright
Previous: Replace URLs from WordPress
...