7 days of unlimited WordPress themes, plugins & graphics - for free!* Unlimited asset downloads! Start 7-Day Free Trial
FREELessons: 15Length: 1.6 hours

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

2.3 Set Up the Blog Entry Type

Hey, welcome back to build a blog with Craft CMS. In the last lesson, we set up the blog categories and the associated fields that we're gonna be using with our blog entries. Now, we're ready to go ahead and set up a blog entry type that we're gonna be using every time we post to our blog. So let's head into our Settings. We're gonna go into our Sections. And, we've already got a couple of sections in here. We've got the Homepage section which is just controlling the homepage that's there by default, and the News section. Now we're actually not gonna need this Homepage section anymore because our homepage is gonna be just populated by the latest blog post. So go ahead and delete that. And then rather than creating a new section for our blog, what we're gonna do is just rework this News section that's already in here. This is already the right type of section. It's a channel, which is what you want if you gonna be setting up something you post to regularly. So first we're going to edit the settings of the section itself, so click on this link here on the left. Now we'll go through make a couple of edits. So we wanna rename this from News to Blog, so we'll do that. And then we wanna change the handle to go along with it. We wanna leave this set to Channel, this is the correct section type that we want to use. Now here is where we get to use that main category that we setup earlier. We're gonna change the way that URL's are generated for entries, rather than having news slash the date slash slug. We're gonna replace this with our main category slug. Now let's just have a quick refresher. Open up in another tab our Settings and our Fields. And, if we have a look at our main category, we can see that this is the handle for our main category, and every post is gonna have one of these associated with it. So we're gonna copy that. And now we're gonna have that category output here. So we're gonna add mainCategory, now this is actually an array by default. So we're gonna grab the first in this array and we're going to grab the slug. So now for example if an entry is in the category shoes and the post title is, my favorite shoes, then it's slug is gonna be shoes/my favorite shoes. So what that does is it gets relevant keywords into your URL which can help you get better results in the search engines. And then the last thing we need to do specify the template that we're gonna use to display each entry. We'll leave this almost the same, but instead of being in a folder named News, we're gonna put it in a folder named Blog. So then go ahead and save that. Our blog section is now done the next thing to do is create or edit our blog entry type. So this is already in here, there's an existing news entry type. We're gonna rework that into a blog entry time. So again we're gonna change the name from News to Blog. And also the handle, we'll leave the title field as it is here just the settings can stay the same. Now, we just need to set up our field layout. So this is gonna determine what the UI use when you creating posts. So underneath the title We'll have the user set the main category, and we're also gonna set this to be a required field. We're gonna need in order to generate a permalink, so we need to make sure that that's there. Then we're gonna add in our blog categories. And in this case we're not gonna be using tags. I know tags are common in blogs, but as far as learning how to set everything up on the backend of Craft goes, the process for working with tags is going to be much the same as the process for working with categories. So rather than going over the same ground twice, we just go through what you need to do with categories and then If you're making a blog and you need to use tags as well, you'll know how to approach it. But for this purpose, we're just gonna remove that. Now that's good to go, we'll scroll up and Save. That's all done now, the existing news channel has been converted into a blog channel. And they're actually is already an entry that we can have a look at and see if all of our changes have applied properly. So if we'll go into the entries, here's our blog channel. And here is the post that's already in your default installation of Craft CMS. So we'll go into that, and here are all the fields that we set up. So we've got a main category here. We can go into our categories that we set up earlier and select the main category for this entry. Let's choose shoes. And down here, we can select all the categories that apply to this entry. So if you hold down Shift, you can select multiple categories at once, and you can apply them. So let's just save those changes. And now we verified that everything is working properly with our blog entry type. In the next lesson, we're gonna be coding up a main index template for the site and that's gonna display all the latest posts in blog. So between now and the next lesson is a great idea or if you just spend a little time adding in a couple of test posts. Just put in anything you like. You can just use placeholder text, it doesn't really matter, just so that you've got something that you'll be able to test with as you're coding up the main index template. So after you've done that, I'll see you in the next lesson.

Back to the top