Using Views To Create A Block

This lesson shows how to use the Views module to create a block that contains a list of node titles that link to their respective nodes.

Bookmark and Share Bookmark or Share Post

Comments

Jim's picture
Anonymous's picture

What's the associated between the block and the view?

I'm still finding views incredibly confusing. In this lesson a block was defined as part of a view, but clearly, the block config page shows that it could have been used anywhere - although Rob selected to use it only on the CCK and views page. If it can be used anywhere then why is it defined as part of that view...what's the connection? Is a view simply a grouping ground for blocks which are set up in a particular way rather than actually relating to a physical view?

I've learnt a hell of a lot about Drupal over the last few weeks. Much of that thanks to Rob's efforts, but I'm still totally stuck on views.

learnbythedrop's picture

Blocks and Views

At it's core a view has two main components: 1) a query to the database that returns items specified by the user; 2) instructions on how to display the results of the query. The most common choices to display the view are probably: a) on a page; b) in a block; and c) via an RSS feed.

My thought process goes like this. I want a page that displays only cck and views posts. So I add a view that includes a query that will return x number of cck and views nodes. I select a display type of page and provide a system path of /cckandviews. So now I've got a page that I can then link to in the menu items.

At some point later (or maybe right then) I decide that I want to have a block available to put a list of recent cck and views posts. I can do that two ways. I can either add an entirely new view from the admin/build/views screen or I can add a block display to my existing query. I chose to do the latter for organizational purposes. But either way would work.

Once I've created my block I can put it anywhere blocks could normally be placed on my site. It really doesn't matter what process I used to create the block at that point.

So there are options when it comes to creating different elements with the current views interface. I can add a particular view query and then configure multiple displays (page, block, feed, slideshow) on a single screen. Or I can add a new query and display for each page, block, etc. from the admin/build/views screen.

Anonymous's picture

Thanks very much for taking

Thanks very much for taking the time to reply to that Rob. To start with I found it strange that a block could be defined in the same view as one which contains 'pages'. It seemed like the block was somehow being linked to a specific page, but clearly, it can be used anywhere.

I'm still unclear about many aspects relating to views - such as why we would add multiple pages to the same view, and the implications of this. How are these pages positioned within the view....or am I missing the point entirely here. Still, it's far clearer than it was yesterday.

Thanks again Rob.

Lems's picture

You mention making Views to

You mention making Views to display Fields, and I've run into a problem with it that I'd like to hear from you on!

Let's say I have a custom content type "Song" with a custom field "Genre" that is populated by a select box. How do I make a view that just shows what the Genres are? I tried this: I made a view to display nodes, and selected the Genre field as the only field to display.

The problem is that the genre appears once for every Song that's been labeled with that Genre! So I get a lot of "Rock," when I just want it to appear once. How can I create a view that outputs my list of Genres?

Thank you so much, and great site!

- Lems

learnbythedrop's picture

Why Not Use Taxonomy?

It sound to me like you could actually assign a vocabulary to the content type using the core Taxonomy module instead of adding a genre field with CCK. Then you could create a "taxonomy view" and the particular genre would only be listed once.

The following link points to a video about Taxonomy. http://learnbythedrop.com/drop/125

Lems's picture

You're a gentleman and a

You're a gentleman and a scholar - thanks much!

Mike's picture

Great tutorial! I must

Great tutorial! I must confess that the UI for Views is very confusing to a novice, but watching you create a simple view demystified the process for me.

Views are incredibly powerful query builders...Drupal Rocks!