Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
By now you have a pretty good sense of how to build queries with the Views module, but there is still one basic area that's kind of hard to teach and that's all the many options you see when you add a Filter field or Sort criterion. That's because while the options are numerous, some of them are pretty are arcane while others are pretty to figure out. We are not going to look at all the possibilities of sorting, filtering and field display, instead we'll just run through a few of the more useful ones to see their effects on our site. The user interface is very similar among those three. So we'll just go through the Filter options by way of example.
We are back looking at our people view, which of course you get to through the Site Building Views Interface I have shown you before. As you know we have already set up the filters so we only see publish nodes of the type person over here. I'm going to add another one so we'll only see those people that have been published and that are of the taxonomy friend, in other words, we'll only see friends of the family. To do that I again click on the Add button here, scroll down, go into my taxonomy group as we discussed groups in other videos, and then click on Term. I want to mention one little tip, the Add Field, Add Filter and Add Sort Options looking awful lot alike, as you can see you can have the same sorts of groups, you see the same list of options and so forth.
More than ones I have been in the middle of a process and forgot what I was doing, I think I was adding fields to the display but was in fact adding filters. Then when I was done I've clicked preview, and after 15 minutes of work the results were nothing at all like I expected. To avoid that get in the habit of checking the text at the top of the options list. In this case we see Add filters as opposed to Add field. There is one other word here I'd like to talk about Defaults. We'll talk about what that means in the video adding view displays as pages, blocks and RSS feeds.
But back to what we were doing, I'm going to add this Filter so we can filter out only those friends. I click on Add, the vocabulary we only have one this relationship to family and I'm going to select drop-down, you could allow people to type-in the selection option but I'm going to have drop-down, and we don't have a hierarchy in our taxonomy, if we did, you could show it this way, but I'll click Update and see what we have. As I said I only want to show those people who are friends, so I'll click there and click on Update. Now we see exactly as we expected only the one person who is listed as a friend. I'll click Save to be sure that everything is set. This seems like a good time to show off one of the Filter tool's most useful features and it's one that it shares with the Sort criteria as well. You can actually expose a control to end users, so anybody can Filter and Sort to their hearts to light. To do that let's go back up to this taxonomy term and click on it. To give our options again you might not have noticed this little Expose button here. All we have to do is click Expose and we get a large group of additional options. Once again I won't explain all of them just a few that are useful.
The easiest way to explain them is actually to show you the results and then
come back and change some of them so you can see what it does, I'll click on
Update as usual. Now when I look down here at our preview we can actually
change the selection, and remember, this is what the user will see. So right
now we are showing only Friend. Let's say we only want to see those people who
married into the family, click on Married and Apply, there they are. We want to
see everybody, we have this
Let's go back up and take look at some of those options click on Taxonomy: Term. Let's get rid of this Force single for example so we could see what that does, un-check it, click Update and go down to our preview. Now we can select multiple terms here and show for example all those people who are both married into the family and raised in the family but not the friends and the pets. You would hold down the Command key on the MAC or the Ctrl key on the PC to select more than one. Click Apply, and indeed we get exactly what we expected. Let's look at a few more of those options, click on Taxonomy: Term, scroll down to our options and let's uncheck the Optional checkbox and see what that does, click on Update.
Now it's taken away that choice to let you show everything, in other words you have to choose some taxonomy term. I'll scroll back up, click on Taxonomy: Term again, and I won't go through all the rest of these options as you can see there are several and they are fairly self-explanatory with the text that appears underneath each of them. So that's how you can expose a Filter. As I mentioned before you can also expose Sort criteria giving people various ways to sort by choosing pop-up menus and selection boxes and so forth. For our purposes though let's remove that option by hiding the Filter from users. Click on Hide right here and then Update and it's back to the way it was, we are only showing friends and we are not giving people an option to see other things.
The last thing I want to do before we leave is I want to get rid of that Filter because it's not actually the way that we are going to use things later in the course, I click on Taxonomy: Term, scroll down, and then I can just click on Remove. Remember, you could also have done this by using that Arrange button right up here, but we can do it one-by -one by just clicking Remove. We see everybody again and click Save. This gives you just a peak into the dozens, if not hundreds of options were changing the sorting, filtering and field displaying views.
The good news is that views has fairly good help commentary throughout its interface and the Advanced help module provide even more. And as always you can get even more instruction on these options by searching on the drupal.org website.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.