Load WordPress post data and create Gatsby pages

Jason Lengstorf
InstructorJason Lengstorf
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 4 years ago

WordPress separates “posts” from “pages”. In this video, we’ll learn how to extend page display code to create post pages and display their content.

Jason Lengstorf: [0:01] So far, we're pulling in our pages, but we also need to consider how we get our posts. To pull in posts, we can follow almost exactly the same process.

[0:10] We'll go in and we can just copy and paste this page-template and we're going to rename it to post-template. In here, we're going to get the post and then we'll swap out here to be post. We'll also rename this to postTemplate.

[0:34] Once we have this, we're ready to modify our gatsby-node. Inside of here, we can take our pages, duplicate that, switch it out to be posts. Then we're going to take this whole section and duplicate that and change it to be posts as well.

[0:54] In here, we want to use the post-template and the uri. For here, we want this to be prefix. We're going to prefix with blog/. Now that we've done this, we can stop and start our server.

[1:16] Once that build is successful, we can pull up the browser. Let's take a look at one of our posts. We can go to blog/WordPress-jamstack/ and we'll see that now our blog posts are loading.

egghead
egghead
~ 12 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today