The Power Of Drupal Views
When people ask me why I would ever use Drupal to build a website instead of other platforms like WordPress or Movable Type I typically have one answer, "CCK and Views." That could be interpreted as two answers but since the modules go hand in hand I'll call it one. I've written about the basics of CCK before so I recommend that you check out that post if you're interested in understanding CCK better. This post is about the Views module.
Views is a module that offers Drupal site developers (you I presume) great flexibility of choices for displaying content. Views provides this flexibility by offering up a graphical user interface (pictured below) that allows you to query the Drupal database for content and choose the format of the content display without having to write SQL queries. I've written plenty of SQL queries in the past for business purposes and if I never write another one I won't be disappointed. If you want a much closer look at the interface I'm speaking of feel free to check out one of my videos that shows you how to do something practical with views.

Views Interface (Drupal 6)
Three Basic Types of Views
There are three basic types of views available in the base module. You can display content as a page, block, or RSS feed. When I say "content" I mean entire Drupal nodes or individual fields. For example, the page at http://learnbythedrop.com/cckandviews is a "view" that lists x number of nodes. When you list the node you get the Title + Body, plus links to comments and any other fields that would display when you are viewing a node. If you choose to display fields instead of nodes, then you can pick and choose individual fields from your nodes to display. For example,. the page at http://learnbythedrop.com/archives displays the Title (linked to the node), (Number of) Views, (Number of) Comments and (Number of) Votes fields.
The one thing that the views mentioned in this paragraph have in common is the fact that they are "page" views. Page views differ from other views because you assign a path (like http://learnbythedrop.com/archives) that displays the view as a page on your site. You can also create your list in a "block" view. When you choose block the content that you add to the view will be available on the block page (at admin/build/block) for configuration and placement just like any other block on the site.
You should put a little bit of thought in to what types of content you display in a block vs. a page. Blocks work well with lists of titles linked to nodes (see the "Recent Drops" and "Comments" blocks in the right sidebar), whereas a page might work best with full nodes or a collection of fields. Lucky for you that the views module has a very handy "live preview" feature that allows you view the results of your query while building your view.
will appear on the page. See the bottom of the page at http://learnbythedrop.com/gallery for an example of how this looks.Style Options
Drupal views also have several standard "style" options which differ depending on the type of view you choose. RSS, for example, is really a style option for your view. But if you choose to set up a page or a block view you have different options as to how the final display will appear. Some examples of style options are unformatted, list, grid and table. If you're creating a page full of nodes then you'll likely choose "unformatted" as your style. But if you're choosing a page with individual fields (like http://learnbythedrop.com/archives) then a "table" style might work best. For blocks that have lists of titles linked to nodes I typically choose the "list" style. Once again, the live preview option is your friend when making these types of decisions.
The "grid" style is an interesting choice if you're displaying just a couple of fields and want to repeat the content across and down the page. I've implemented this style on my view at http://iheartmets.com/metstweets, which shows a grid of recent tweets about the New York Mets.
Display Controls
Drupal views provides very good control over exactly what and how content is displayed. The "filters" section allows you to indicate the rules for displaying content. For example you can choose to display only a certain node type. Or you can only display posts from a particular category. You can mix and match the controls to select, for example, only blog nodes with a category of "dogs". You can also choose to only display nodes that have been published, which would exclude posts that have been saved as drafts. That's probably a good idea.
You can also control the sorting of your content. You can sort based on any number of fields. For most things, but not always, I choose to sort based on the post date, descending so that the newest content shows up at the top of the list. You can also choose to display content in the order that things were updated so every time there's an update that content moves to the top of the list.If you are creating a view that is displayed in a table you can also make each of the headings sortable to the user as I have done over on http://learnbythedrop.com/archives.
Additional Features
While the views module has many valuable features that come standard you may also want to explore some of the other modules that extend the features of Drupal views. I've listed some of my favorites below.
- Views Slideshow allows you to display the items in your view as a slideshow. This works great with photos (see this example) but will also work with text as well. I've got a pair of views slideshows running on the front page of http://iheartmets.com. The views show a rotating lists of tweets and podcasts.
- Views Accordion allows you to display content that opens up when the header is clicked. I'm using this module on the page at http://learnbythedrop.com/gettingstarted.
- Media RSS is a very useful module for image publishers. It adds social tags that allow the photos you publish to be easily picked up by subscribers and other websites that import your feed. I'm using this module on my image gallery feed at http://learnbythedrop.com/gallery/feed.
- iTunes lets you publish iTunes compliant podcast feeds, which provides a homegrown alternative to using a service like FeedBurner.I'm not using this one right now but I am working with it on a test site.
There are also many other modules that add options which allow you to do more with views. For example when you add a rating module, like Plus 1 for example, you get the option to access the voting data via views and present that data as I've done on http://learnbythedrop.com/archives. If you want to browse and keep up with all of the possibilities for adding on to views I suggest that you check out the views module category on Drupal.org.
Learning More
There's a lot to the views functionality and it's a very important part of any Drupal site that seeks to move beyond very basic publishing. While you can build a pretty good site without using views there will likely come a time when you want to see something displayed differently. And when that time comes you don't want to be fooling with SQL queries in order to make it happen. So I recommend that you first become a student of the basics of views (and it's companion module CCK), trying out the features on a test site until you feel confident to start working on a production site. The time you put in will be well worth the effort.
The team at Lullabot has a views video product that may be able to help and they have posted a pair of free chapters so you can get a taste of what they have to offer. I've got my CCK and Views page (created with views of course) which offers you some more learning as well.
Good luck and please let me know your thoughts, comments and questions about the views module in the comments section.
- learnbythedrop's blog
- Login to post comments
- 39111 reads


Comments
Great article on Views
I enjoyed this view of Views. It gives a great view on your site and another on the structured learning method that you've created. Thanks.
twitter to drupal?
Hi,
Great insights on views. May be touchiong views filtering and arguments is an add on!
Referring to: "The "grid" style is an interesting choice if you're displaying just a couple of fields and want to repeat the content across and down the page. I've implemented this style on my view at http://iheartmets.com/metstweets, which shows a grid of recent tweets about the New York Mets."
==> How did you get the tweets into drupal nodes please?
Thanks for sharing this info in advance
Greetings, Martijn
Feed API To Import Twitter
Each Twitter search has an RSS feed that accompanies it. So I used the RSS feed from a search for the term "mets" on Twitter and import it using the FeedAPI module. http://drupal.org/project/feedapi
views
Ok, I'm using views, imagefield, imagecache, filefield, taxonomy. I have created four photo galleries, images are uploaded, galleries show in my primary menu fine. Final hurdle has me going buggy. Each gallery shows as a summary view that shows all the galleries and the number of photos in each, which when clicked on shows the appropriate thumbs, which when clicked on shows the appropriate preview. How can I bypass the summary step and have the thumbs show directly in each gallery. I'm new to this and have been going round and round with this. Your site is fantastic, it has guided me through everything so far. Thanks in advance.
Mark
Bypassing Gallery Summary
I'll go for an overly simple solution and suggest that perhaps you adjust the primary menu to point to the url of the sub-gallery as opposed to the higher level summary gallery. I'm not sure how the summary gallery got created. A screenshot or link to a live site that shows the summary gallery would help me provide more insight into how to eliminate this problem.
Regarding views
Hi,
First of all Thanks for posting great tutorials for the drupal CMS.
I wanted to know how we can create number of comments using Views. I have developed image gallery using CCK and views, How can I show number of comments?
Thanks
Number of Comments
Showing the number of comments is a theme issue. See the following link on Drupal.org which provides a snippet that you can insert into your theme that should display the number of comments. http://drupal.org/node/253284
Limit the number of comments
Can you explain on how to limit the number of comments to show? For example, I have a view that pulls the body of the node and the comment body -- but I only want the latest comment (one comment) to show.
Limiting Comments Shown
I have to say I've never thought of doing that. Thus, I don't have an answer. You might want to start by checking out the following module and seeing what discussion has occurred around it. http://drupal.org/project/commentcloser
im DYING here. does ANYONE
im DYING here. does ANYONE know how to style & theme the views pager?
Re: im DYING here. does ANYONE
Did you get a response for this? I'm also dying trying to figure this out.
Re: Styling Views Pager
The best I can do, since I'm not in any way good with theming, is to point you to the theme guide on Drupal.org at http://drupal.org/theme-guide/6. It also might help to reach out to the theme development forum at http://drupal.org/forum/3.
Good post
Good overview of views there Rob. A few months ago I was really struggling with the whole concept of views but now I find it indespensible. It's currently helping me with adding multi-lingual content to my site.
Oh, by the way. You provided a link to a slideshow, but I saw no slideshow on that page.
Rich
View Slideshow
Thanks. If you're talking about the link to http://iheartmets.com there is indeed a slideshow there. It's not an image slideshow though. What you'll see is tweets that mention the Mets fading in and out. You can use views slideshow for text as well.
Feeds
I'm still very new to Drupal, our site was set up by a friend of mine. I had him turn on the feed function for the entire site to use for Google sitemaps. It came out as a mrss feed. Is that what you were talking about the Media RSS?
Media RSS
I'm not really sure what has been done there. Media RSS feeds are those that include "media" tags that typically are used to annotate images in feeds. Since Drupal doesn't support Media RSS without an added module I'm inclined to think that you don't have Media RSS enabled. The one way to know is to check the feed and look for the media tags within the file.
Thanks, the article is greate
Thanks, the article is greate and helped me to begine with views..
User Based Filtering in Drupal
Hi! Thanks for the article. It's a great article to get started with views. I have some related requirement and I think it will help others too. I have content type let's say Family Members and only users with the role FAMILY can create content of that content type. I made a view in which I can see the list of all the contents that is FAMILY MEMBERS content that has been created by any Family Role User.
But what I want is that, the user should be able to view the list of only those Family Members content which he/she has created and not others created content. I am using "Content Access" module but still I din't find how to do that with views.
Is there any way we can do that?
Regards
FAS
Views Accordian Rocks!
Thanks! I did not know about Views Accordion. Your reference page is a great demo. I have several sites that could benefit from the module. Time to work on my sites!
Feed Views List
I've been scouring the web and I can't find an answer, so I'm hoping you might be able to help me out. I've added a few views which list particular content types. For each of these views I've added a Feed view type. I'd like a block on my site that lists all of the available Feed Views so that people can subscribe to any feed from any page. Is this at all possible without manually creating a menu?
Listing RSS Feeds
I haven't tried it myself, but if you haven't looked at it already you should look at the syndication module. http://drupal.org/project/syndication
Views
Hi!,
Let's say I have two content types.
1. User
2. User Video
Now User Video has a Node reference Field which points to the "User" content type nodes. But what I want is that to make a view or link to be displayed on the User Node that will display the User Video Node where the node was referenced from.
Simply means the link field in the User Content type should only open the User Video page from where that particular User was referenced from.
What will I have to do with the views?
Thanks and regards
Views Referencing
This is one of those things that I would almost need to see a picture drawn of the relationships to know how it should be set up. It sounds like you're using a content type as a proxy for the user profile which is something I haven't done. I've always used standard profiles.
Query
Hi rob!,
Thanks for the reply. Well no I am not using my content type as a proxy for the user profiles, I just named it as an example. I just have two content types, 1.Room,
2.Room's Video.
Now the Room is for room's info and the Room's Video is for the Live Cam Feed coming from that room.
The user first makes all the Room's content. Then he makes the Room's Video content and selects a Room content from the Node Reference field availabe in the Room's Video content. And so on. How can I make a view and embedd it in the Room's content so that it will show only that Room's video content where the Node reference field value equals the View's container Room content.
Hope the picture is clear now.
Thanks and regards
Re: The Power Of Drupal Views
Very helpful series of tutorials. Thanks.
Reference 7 in this post refers to http://learnbythedrop.com/archives; and the sorting of rows in a table. With Mozilla 3.5.7 the sort did not happen for any of the columns (title, views, comments,votes).
Browser problem?
Geoff.
Table Sorting on Archive Page
Thanks for pointing that out Geoff. I have to investigate. It might be related to my new theme because I'm having the problem too.
Table Sorting on Archive Page Fixed
I finally got this fixed. I posted a query on Drupal.org and a user there came up with an idea that got it straight. http://drupal.org/node/720002#comment-2691462
It's important to keep in mind that there is a sort option for the view and also for a table, if that is the layout you choose. The table sort and the view sort were conflicting. So I removed the view sort and set the table sorting as I wanted it to be.
Re: Views Slideshow - The Power Of Drupal Views
Hi Rob. Thank you for such a nice overview of views, really helpful. I know that the slideshow at: http://californiawatch.org was implemented by using the module "Views Slideshow" you mentioned in this article. Do you know how to get to display the tabs below the pictures and also the text on the right?. I haven't been able to do it. Your help is most appreciated. Thanks!!
Re: Views Slideshow
I think that functionality is related to something called Views Slideshow Thumbnailhover which is referenced on the views slideshow module page at http://drupal.org/project/views_slideshow.
how to Style Views pager
Do you have any quick instructions on how to style the pager links within a view? I can use jquery to style the links on the initial load of the view, but once the next page is clicked, it reverts to default view style. Please help if you can, I'm going crazy. I've heard drupal.behaviors is the way to go but i have no idea what that means. Thank you.
Re: how to Style Views pager
I don't have a quick answer. I've always just accepted the pager that comes with a particular theme.
Re: how to Style Views pager
Thank you, that's an answer (one i like actually) even if it's not what the powers that be want to hear :)
Re: The Power Of Drupal Views
I really enjoyed the post...
Was looking for something that would actually help me start working on a new project and Views did it for me.
Cheers
last cooment published
How can i make a block with only last comment published. I don't find in views filter a field for published comment
Re: last comment published
When you go to /admin/build/views/add you need to select the "View Type" of "Comment" and then you will be able to create a block with one or more comments in it.
Re: The Power Of Drupal Views
Is it possible to get rid of those default fields (e.g, title, file attachment) in my new content type? thanks for reply
Re: The Power Of Drupal Views
Yes. If you edit your content type in the 'workflow settings' section you can choose to set attachments to 'disabled'. You can also use the Automatic Nodetitle module (http://drupal.org/project/auto_nodetitle) to hide the title field and also create an automatic title based on other fields in your content type.
Re: The Power Of Drupal Views
Thanks for your reply. but file attachment and title is not the only problem. they still have menu setting, common setting, Revision information, bookline etc that I dont need. Do I have to eliminate one by one by using their own module configuration or is there other way to do it? Please let me know either way. thanks I really appreciate it.
Re: The Power Of Drupal Views
Those are shown because of the permissions you have set. If you take away "administer nodes" in the settings at '/admin/user/permissions' then those options will disappear.
Views or image has a bug !
I have to disable views when using the 'image' module, as i wish to have all photos on one page. With views enabled for image gallery, views will publish only 6 photos per page, then creates a new page of 6 photos etc. When views is disabled, I can change image gallery to display how ever many photos i like on one page.
It's a pity, as i would like to use views to change the photos around allot. But I really like the lightbox feature of the image module.
Thanks for a great explanation of views. People try to tell you too basically, or too complicated. Like; drupal helps you build a website! then they start to talk to you in php !?!
Re: Views or image has a bug !
"views will publish only 6 photos per page, then creates a new page of 6 photos etc." Check the settings of your view. In the "Basic Settings" section look for the 'Items per page' variable. I sounds like it is set to 6.
The Feed Latest Updates block
Hi!
I am Big fan of this site. Great work!
I am facing strange problem here. I have created a feed aggregator source and I have enabled its block. The permissions for the block in the block configuration has been set to no role types i.e all role types are "unchecked" so making to viewable to everyone. However I can only view it when I am logged in and when I log off, the block is gone. It's kind of confusing.
Please help me what I am missing.
Regards
Re: The Feed Latest Updates block
Check for global permissions for the Aggregator module at /admin/user/permissions.
Re: The Power Of Drupal Views
Hi,
Fantastic tutorial as all of the stuff from learnbythedrop is. I have been sruggling with something that I'm sure should be fairly simple. If you create a view of say six treatment categories, ie Eyes, Hair, Face, etc, output as images on views fluid grid. What I want to happen is when you click on an image it takes you to another view which lists all the nodes within that category. A good example is on http://www.one2oneclinic.com/
If you click on the menu item Treatments, you will see what I mean.
Many thanks,
David.
Re: The Power Of Drupal Views
Good question. I can't tell you exactly how to do it but I do believe that you want to utilize the features in Views Relationships. Here are two links that will give you more information on Views Relationships. http://drewish.com/node/127 | http://gotdrupal.com/videos/drupal-views-relationships
Re: The Power Of Drupal Views
Dear Rob,
Do you know how to put ipaper under a tab? I have troubles doing that. Please help me.
thanks
Re: The Power Of Drupal Views
I'm not sure what you mean when you mention ipaper.