-
Notifications
You must be signed in to change notification settings - Fork 4
Pages, Posts, and custom Post types
Page/Post data lives at /wordsby/data/collections.json
in your gatsby site. This file is updated via github or gitlab api every time you save a page or post.
Wordsby uses the WP permalink structure you've set up in your WP install. The base url is stripped from all links and the leftover pathname is used to create Gatsby pages. This means any regular WP internal links or menus will just work out of the box.
Instead of an endpoint for each post type, Wordsby puts all post types and pages onto a single endpoint.
It's available at wp-json/wp/v1/collections
.
Query it like so:
query HomeTemplate($id: Int!) {
wordpressWpCollections(wordpress_id: { eq: $id }) {
post_title
}
}
or
query BlogTemplate($post_type: String!) {
allWordpressWpCollections(filter: { post_type: { eq: $post_type } }) {
edges {
node {
post_title
}
}
}
}
All single pages receive pageContext containing the next / previous post. The data contains post type, pathname, page title, and wordpress ID.
For next / prev posts links in a blog you can access this data and just check if the links are of the same post type of the current page to only show next / prev links within a post type.
{
!!nextPost && nextPost.post_type === "case_study" && (
<Link to={nextPost.pathname}>{nextPost.post_title}</Link>
);
}