FREELessons: 15Length: 1.6 hours

Next lesson playing in 5 seconds

  • Overview
  • Transcript

2.2 Prepare Blog Categories

Our blog is going to be using categories in two ways:

  • One, to organize our content as you usually would on a typical blogging platform.
  • Two, to allocate a ”Main Category” per post we will then use to generate search-engine-friendly permalinks on our blog entries.

In this lesson we’ll set up our blog categories to allow for both of these functions.

2.2 Prepare Blog Categories

Hey, welcome back to Build a Blog with Craft CMS. In this lesson, we're going to be going through and setting up categories for our blog. We're going to be using these categories in a couple of ways. One, we'll just be using them as you would on any blog, just to help you organize your posts. And the other thing we're going to do is set up a main category that you'll set per post. And then we're gonna be using that main category later on to create search engine friendly permalinks. So the first thing we're gonna do is jump into the Settings area, and then we're gonna look for this Categories button here. Now we're gonna need to set up a category group. You can have a bunch of different types of categories in a Craft site, and in this case, we wanna set up categories that are specific to our blog. So we're gonna go New category group, and then we're gonna give our category group a name, in this case we'll just go with Blog. And we're gonna give it a handle, we'll just change this to blogCatGroup. And then down here, we're gonna set up the permalinks for our categories. This is gonna be the permalink that will allow you to go to a listing of all the entries under a particular category. So we're actually gonna change this to category/slug, and then that slug is going to be the slug of the specific category that you're visiting. Now we've just changed this to this format because the category/slug format is the one that I've seen most commonly used in other blogging platforms. Now we just need to specify the category template, and this is something that we're gonna set up later, to display the listings of entries that fall under particular categories. And we're gonna put this in a folder named blog. And we're gonna have a template named Index. So that's everything for this one, and we'll save that. Now our categories ready for use. So you can see this new item has appeared on the menu here, categories, so click on that. And now we can go ahead and set up some categories. So let's have one, just pick something random, let's just say Shoes. So there's our new category here. You can also add subcategories. So let's add another one, let's say Sneakers. And here, you could use a parent, so choose Shoes there. Now the other thing that you can do, if you want to set a subcategory, is just create it like normal. And then once you've created it, you can drag and drop it into a different position. So go ahead now and just fill in a few categories, so you've got something to work with later when you start setting up entries. So now I've just set up a few categories and subcategories for us to work with. Let's go ahead and now create the fields that we're going to use to build our blog entry type out of. So we'll jump into Settings, and then into Fields. We're going to need two fields to correspond with each of the two ways that we're going to be using our categories. So first we'll just set up the general blog categories. So we'll go new field, and we'll call this one Blog Categories. Go down to Field Type, and we're gonna choose Categories here. And this has automatically pre-filled the source in, as our blog category group. We only have one category group right now, but if you set up more, obviously, there will be more to choose from here. So now that is good to go, we'll save that. Next we want to set up a main category that we're going to be using to generate our blog post's permalinks. So we'll set up another new field, this one we'll call Main Category. And it will scroll down and we'll choose Categories again, and the source is our blog category group. This time, we want to set the limit to one, because you can only have one permalink per post. So that means you only want to have one main category, whose name you're going to use in that permalink. We'll just include a little instruction here. We'll just say set the main category for this post to be used in its permalink. And they will go ahead and save, and now that's everything that we need for our blog categories. So now we're all set to go through and set up our blog entry type, and that's what we're going to be doing in the next lesson. I'll see you there.

Back to the top