This course has been updated! We now recommend you take the Introduction to Gatsby, v2 course.

Check out a free preview of the full Introduction to Gatsby course:
The "Getting Posts Q&A" Lesson is part of the full, Introduction to Gatsby course featured in this preview video. Here's what you'd learn in this lesson:

Jason fields student questions about folder structure and how to create multiple post types.

Get Unlimited Access Now

Transcript from the "Getting Posts Q&A" Lesson

[00:00:00]
>> Jason Lengstorf: Yes.
>> Speaker 2: I just wondered about you've got each post in its own subfolder. Is that necessary for the MDX thing to-.
>> Jason Lengstorf: No, so anything that you put into this post folder will get pulled out in red. The reason that I'm doing this is because later on I'm gonna add images and I would like to have the images for a given post in the same folder as the post that uses them.

[00:00:30] It's much easier for me to keep track of, and also I'm gonna show you a little convenience thing that Gatsby does when we get there that every time I see it, it just makes my heart smile. Yeah, go ahead.
>> Speaker 2: So, in this instance you have one type of post.

[00:00:46] What if you wanted multiple post types?
>> Jason Lengstorf: Yes, if you had multiple post types, you would end up writing a slightly different query. So for example, you might end up saying, let's say we wanted all file where we would filter and say that we want the source instance name to be posts.

[00:01:09] And then this is where gets really powerful because now we can say child or nodes and then child MDX and then front matter and title, and so, where'd I do wrong? Source instant, no, needs to be equals.
>> Jason Lengstorf: That's the wrong button. This is the right button. Go away.

[00:01:38]
>> Jason Lengstorf: There, so this is where we're kind of displaying a relationship where we're looking at the files. And do you remember when I said that we set a name on our Gatsby config to be post? We're basically saying give me everything named posts. So if you wanted to create another one that was called recipes or docs or whatever, like whatever you wanted to create, you could create another folder or even have a sub folder in here.

[00:02:07] A pattern I see is content/post, content/docs. And then instead of doing path posts, you can do content/posts and then this is named posts. In that way you're able to kinda filter down to just what you need. Does that make sense?
>> Speaker 2: Yeah, so it would just be in your, in the query.

[00:02:29] You wouldn't have to change anything in your config.
>> Jason Lengstorf: Well, yeah, you would.
>> Speaker 2: Or would have another section?
>> Jason Lengstorf: Yeah, you could just duplicate this and say this one is docs, and this is gonna point to a folder called docs. And then you'd be able to query for the source instance name of docs, and that would pull up anything in the docs folder instead.