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

3.1 Creating a Page View

So far, you've learned how to create individual pieces of content, but what about if you want to group together multiple pieces of content based on some criteria? That is where the concept of a view comes into play. With views, you are able to quickly and easily create groupings and filters to create a collection of content. Let's go!

3.1 Creating a Page View

Now, that we've began to add additional content to our site. You're probably gonna want to start asking yourself the question, how can I start to organize this in a way that's easy for users to get into my site and see the most relevant information to them that they possibly can? And how can I structure and organize my data? In such a way that to make that as easy as possible. And the answer to those questions is through views. Now right now we have roughly 50 content types or nodes shown within our site. And this is great, but the problem is if I wanna go and find anything of use to me, I'm gonna have to start to sift through all of this content. Did I find anything on page one? No, I guess not. Now I have to go to page 2 and that's not very useful. So what views are going to allow us to do is to create a series of criteria and then take the data that falls within that criteria and puts it somewhere easily accessible on the site. And there's two general ways that you will typically do that, although you can do it in different ways from those two but two ways that are actually fairly useful that you will find used most often. So, let's take a look at views. So, I'm going to go back up to Structure and I'm going to come down to the bottom and I'm going to select Views. Now, here are some views that are installed and created and enabled by default and a lot of these you've actually seen you just didn't realize that those work views within Drupal. One of the main ones we've seen quite a bit is actually Content. The content view that we've been working with is actually a view. So, if I already click on this path, it's gonna take you here. We've been here many times, which means that this entire page here is actually a view that is provided by default through Drupal. So let's go back and we'll see a couple of the things there are Files we've seen that. We've seen People, and we're gonna see that a little bit more in the near future. And a number of others in here as well as a few Disabled at the bottom Archive and Glossary. So now we wanna do is, we wanna start to create our own custom views to put some of the most relevant, maybe most recent data of certain types out onto some sort of maybe navigational link. Or maybe on a block in the side bar or something like that, to make things easy for the users to see. So let's go ahead and add a new view and we're going to start by creating a View name since that's required. So in this case we're gonna call this Latest Content and this is just a general name you can call this anything this is just a sample for now. And now we can specify the view settings, we want to show Content and you can show any other type of configurable information found within your site. But Content is where we're basically concerned with right now. And of type and you can select the content type so I'm going to say, of My First Content Type, but you could select anything that you want. So I'm gonna select to that and I can sort it in any sort of way that I want either unsorted, Newest First, Oldest First or by Title. And I think Newest First probably makes the most sense. And now what I also wanna do here is, I wanna specify that I wanna Create a page. Now the reason I wanna do this is because I wanna create a brand new page. That uses these view settings to show some very new and relevant data to the end user. Every time they log on to my site, I wanna put a link at the top of the page in the main navigation section and show them some of the latest content. Now that page that I'm creating, we can specify a title. In this case, I'm just gonna call it Latest Content but you could call it anything that you want. It doesn't have to be the same as the View name, you can name in anything you'd like. Give it a Path, I typically stay with the default and then we can give it some display settings we can make this an Unformatted list, the Table, a HTML list or a Grid. I'm gonna leave in as Unformatted list and we can specify what we wanna show. We wanna show just the teasers, the full post, titles, titles that are links to the actual content or the fields. So I think I am going to stick with teasers, I think that makes the most sense here. And how many items do we want to display? We could go with any number here. I think 10 is probably a decent number. We wanna show maybe the latest 10 or maybe just the latest five. I think 10 probably fine and we can specify whether or not we want to use a pager. And I think we probably, and this case don't really want to but we could, we're gonna throw it out there. I think just so that we can show that we can show paging within these views. And then I think that should be pretty good. We also do wanna create a Menu link as I do as I mentioned before we wanna put that in the main navigation. So within the Menu we're going to select the Main navigation and the link text once again is gonna be Latest Content. And then we can include an RSS feed. I don't think that's absolutely necessary and the block no we're not gonna create a block for this. We're just going to specify this as a page. So let's go ahead and click Save and edit. And this is going to take you to the view edit page. And within here, we can see that we're gonna create a display that's of the page type and the title is Latest Content. The format is an unformatted list we can go back and change that where we're going to show Content just the Teasers. We don't have any specific fields in this case, but we could add fields if we wanted to. And we have a filter criteria where the Published the published status is Yes. So we wanna make sure we're only showing published content where the Content type is equal to My First Content Type. And then once again, we are sorting this by the Authored date in descending order. So we're gonna show the newest first. Now once again we can come in and change all of these things we can change any of the paging settings most of the stuff we've seen in the previous page but this is kind of like your last chance to go ahead and change this right now before you add it in. But of course you can go back and change this at any time. So let's go ahead and hit the Save button. And we're gonna come back down to our display and we also can see a sample preview here which seems to be in pretty decent shape. So let's go ahead and go back up to the top, go back to our site, and now we see Latest Content in our main navigation. Let's go ahead and select Latest Content, and there you have it. Now we see all of our data here. But one thing that's quite interesting here is that, it looks to me like it's showing most of the content, which is actually showing here, and not just the teaser data. So what we're going to do is we're gonna make a small modification to shorten what we're showing here in the next lesson.

Back to the top