Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Pages, Posts, and custom Post types

Tyler Barnes edited this page Jan 5, 2019 · 2 revisions

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.

Permalink / Path Structure

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.

One "collections" endpoint for all Pages, posts, and custom post types

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
      }
    }
  }
}

Next / Prev posts

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>
  );
}