Unlimited WordPress themes, graphics, videos & courses! Unlimited asset downloads! From $16.50/m
by
Lessons:33Length:3.7 hours
Drupal 8 1
  • Overview
  • Transcript

5.5 Working With Taxonomies

Previously, when discussing articles, we noticed that we could add tags. Tags are just a freeform way to add descriptors to content that can later be used to group content together—for example with views. The problem with tags is that they are just that, freeform. What we need is a way to better define specialized tags that have predefined values to make sure that our tagging system is cleaner. This solution is called a taxonomy.

5.5 Working With Taxonomies

In this lesson I wanna take a few moments to introduce you to another topic that we kind of glossed over earlier in the course, and kind of introduced in a little bit of a sideways fashion as well. So when we were discussing adding an article node to the website, you notice that when we went in there and added those, you could enter in this concept of tags. Which was really just a comma delimited list of words that kind of described the type of content that was there. And then we could use those tags to basically group things together. So I could view all of the articles that were tagged with Drupal or something along those lines. Well this is a good idea in practice or in theory anyway. But in practice, we do tend to struggle a little bit with this concept because we are often times running into the situation where we could have some spelling mistakes. So let's say in one instance we wanted to add a tag to an article that said Drupal. And we spelled it correctly in one instance. And in another article we spelled it incorrectly. And this starts to cause problems because now that we've added these tags to our system, Drupal will remember them and then ultimately we could start to tag articles improperly. By different people using the improper tags, maybe one that is spelled incorrectly, and then we have a whole mess of cleanup that we have to take care of, and this is really a nightmare. Well, a way around this is to use what's known in Drupal as taxonomy. Which is a similar concept to tags, but it adds a little bit more functionality around it and can often times kind of save us from ourselves. And so now wanna show you a little bit about what that looks like. So let's come in to Structure, and we're gonna to come down and we're gonna select Taxonomy. Now in here, as you can see we have this concept of tags, and we can actually go in here and list the terms. And what you'll notice is it's going to remember the tags that I put into the articles earlier in the course. And I left themes here specifically to show you that just because you type in text, Drupal is very smart and it's going to remember these things. And it's going to create this taxonomy vocabulary which is known as tags, and then to that vocabulary you add a list of terms. And that's basically what's going on here. So we can actually go back and take a look at this and we can begin to add in our own vocabulary. So instead of just having tags, I can add in my own. In this case I can really call this anything I want, but the way that I'm thinking about this is maybe we want to create a vocabulary using a taxonomy that's going to describe the topics that are going to be shared at a particular conference. Or maybe you could do areas of expertise for speakers or things like that. Or we could even go back and change our user groups to have a taxonomy of maybe levels where we have beginner, intermediate, advanced and things like that. So there's just different ways to achieve these things, and I'm gonna show you where this really starts to add some robust functionality to our site. So let's go ahead and create a new vocabulary and I'm gonna just call this Topics. And this is going to represent the topics that are shared or maybe covered at a conference. So typically, when you go to a conference, the conference is going to be about a specific either, technology, or a language, or a library, or a framework, or something along those lines. And it would be very nice to know what exactly is going to be covered at kind of a high level. So I could maybe filter down the conferences, to find only the ones that pertain to technologies or some other topic that I really like to be a part of. So let's go ahead and save this, and now I have a new vocabulary called topics, and I can begin to add terms. Now I could sit here and add terms for days, and I'm sure you could think of a million more that would be relevant to put in here. But I'm just gonna start to build this out, and I'm going to show you what this is kinda used for. So I'm gonna keep this fairly high level, and I'm gonna call this maybe Security, maybe security is gonna be a topic. And I can give a description to this if I want. I don't have to, it's not required. I can define relations at this point which I'm not really interested in doing at this point either. And this concept of URL aliases, I don't really need right now either. So let's just go ahead and save this. And now I can give another one if I want, so I can continue down this path, which is actually kind of nice. It doesn't take me back to list every time. So Drupal kinda knows that once you create a taxonomy, you could be adding terms for a while. So then, maybe let's call this Software Architecture, and I can just go ahead and hit the Enter key, and it'll go ahead and add that for me. Maybe Database Design, and we could continue going down this path for a long time. So I'll leave it up to you to maybe think of some additional terms to add to this particular topic's taxonomy if you would like, or create your own, that would work just as well. All right, so now that we have these, I can go back into my Taxonomy, and you're gonna see now that within my Topics I can do a List, and I can see Database Design, Security and Architecture. And I can sort these in any way that I want. So maybe Security I wanna have first, and then Database Design, and then Software Architecture, and I'll go ahead and save that. So now let's go ahead and use this taxonomy, within our conferences. So I'm gonna go back to Structure and I'm gonna go back to Content types. And I'm gonna go to my conferences, and I want to manage fields. And in here I wanna add a new field. And I'm going to once again select a reference, but this time I want to reference a taxonomy term. And this is going to be Conference Topics. And let's go ahead and save this. And once again we could make this unlimited, because we could have a conference that covers multiple topics. And maybe there are breakout sessions and all those sorts of things. So obviously you can really begin to grow this as much as you really want to. And we'll set it to a Save Field settings, and now I can set help text, I can say whether or not this is required, which is probably a good thing to require. I can set some defaults, and once again I'm going to select the Default reference method. And I want to enable a particular vocabulary or multiple vocabularies. So in this case I want to say Topics. So let's go ahead and Save settings. So as you can see now I now, have Conference Topics, which is once again an entity reference. So now at this point I think we've done a pretty good job of building out some content types that are really going to drive the content of our site. And now let's try to add in some content, just to see how the basic layout of all of this is going to look.

Back to the top