Welcome to the Geeks & God Static Archive. Read more »

Limit Views-created block content by node author or current node

User Rating:
4.44944
Average: 4.4 (89 votes)

In Drupal 6 sites, Views 2 enables the creation of Blocks that can display lists of a wide range of site content. It is not immediately obvious, however, how to limit the content that is displayed in a block to material written by the current author. Likewise, when making a block that displays CCK fields, it is not obvious how to limit the source of this content to the values of those fields for the node currently being displayed. This tutorial shows you how to do both of those things...

Scenario One: Limit by author of current node

The steps below assume you already have created a block display that is displaying on a node page or series of node pages, that currently is displaying content from all site authors. The steps described require Views 2 and Drupal 6.x.

  • Edit the view in question (Administer > Site building > Views and click "Edit" for that view).
  • Select the particular Block display you want to edit (or edit the default if there are only Block displays and you want it to apply to all of them).
  • Click the + next to Arguments to add a new argument. Limit to User under the drop-down and tick/check User:Uid. (You might think that User: Name is what you want here, especially as the comment text says "The user or author name" but no, that doesn't seem to serve our purposes here.)
  • Click "Add".
  • Fear not! You can ignore most of what you are presented with here. Look at "Action to take if argument is not present:" The option you want—bizarrely named as it is, is "Provide default argument". Click that to select it.
  • You are then presented with additional options that to me seem somewhat surprising for a "default argument"... Select here "User ID from URL", and more importantly then tick the further option that appears: "Also look for a node and use the node author". Congratulations, you've found the secret hidden passageways to the control you require!
  • Click "Update" at the bottom of all these options.
  • Click "Save", which is no longer greyed out now you have made a change with your "Update".

You're done. If you've followed these steps correctly, you should now have a working block that is limited to content posted by the author of the current node. Congratulations!

 

Scenario Two: Limit source to CCK fields in the current node

In this case, you have a series of CCK fields in a Drupal 6 content type that you want to display in a Views-created block on your page, rather than in the main body of the node. You may be wishing to duplicate content also displayed on the page itself, or you may have hidden these fields in the full node by editing the "Display fields" section when editing your content type.

The steps below assume you already have created a block display in Views 2 that presents those CCK fields, but currently the block draws the content of those fields from all nodes of that content type, when you want to draw it just from the current node. The steps described require Views 2 and Drupal 6.x.

  • Edit the view in question (Administer > Site building > Views and click "Edit" for that view).
  • Select the particular Block display you want to edit (or edit the default if there are only Block displays and you want it to apply to all of them).
  • Click the + next to Arguments to add a new argument. Limit to Node under the drop-down and tick/check Node: Nid.
  • Click "Add".
  • Fear not! You can ignore most of what you are presented with here. Look at "Action to take if argument is not present:" The option you want—bizarrely named as it is, is "Provide default argument". Click that to select it.
  • You are then presented with additional options that to me seem somewhat surprising for a "default argument"... Select here "Node ID from URL". Again congratulations, you've found the secret hidden passageways to the control you require! Note that it does not matter if your node aliases mean that the URL you see for the node does not contain the node ID. This argument looks at the underlying "true" URL that Drupal uses that does contain the node ID.
  • Click "Update" at the bottom of all these options.
  • Click "Save", which is no longer greyed out now you have made a change with your "Update".

You're done. If you've followed these steps correctly, you should now have a working block that is limited to content from the current node. Once again, congratulations!

I hope this is useful... comments and any possible improvements in the approach most welcome!

Good Views Tips, Thanks!

5

Duncan,

Nice tutorial. You've given us a handy reference for settings that aren't very easy to find, and I can think of some cool uses for both of these. Thanks!

Micah

This is great....

5

I recently ran into a situation where I wanted to display nodes with the same taxonomy term as the current node. I found the following link helpful: http://drupaleasy.com/blogs/ryanprice/2008/06/usin...

It's similar to what you describe here.

Thanks...

5

I appreciate the tip.

Worked like a charm

5

Yup, that was the ticket.

Remarkably useful

5

Well written, easy to follow and a remarkably useful tip. Well done.

Same thing but with rss

4

This is a pretty cool tutorial. One of the things I've been trying to do is add and rss subscription into a block on users' blog posts. This seems like the way to do it, but I keep attaching a feed to the block and getting a rss link for "all" rather than just the author of the blog post you are reading. Kinda getting frustrated that I can't figure out a simple way to do this.

Been working on this all day

5

and couldn't get it to work till I found your post on drupalsn.com that linked here. Was trying to create a block of nodes with a node reference to the current node - same basic concept as scenario two. Very nice tutorial.

Clint "The Geekin' Deacon" Eaker
Webmaster - Chapel Hill Bible Church
Chapel Hill, NC

Thanks man! I was looking for

5

Thanks man! I was looking for hours trying to figure out how to do this!! You da man!

Thanks!

5

Add me to the list of grateful readers!

Helped me to not go crazy

5

Views2 - the best adventure-module of Drupal6 :-)

Still not working

5

Hello everyone,

I have followed exactly these steps but is is not working to get a block to show the blog posts of an user on their blog page. Is there any reason why this would not work for a blog as opposed to a normal node?.

Any help would be very appreciated. Maybe I am missing something simple.

Not getting this to work

4

Hi! I've seen this solution on a number of sites, but I just don't get it. It doesn't do what I want it to do.

I have a content type (Product Group) that has a lot of fields. I want selected fields to be displayed based on the path.

For example:
The path "/products/drummachine/overview" should select the node "drummachine" and show the field "overview" for that node. So, the second argument is the node and the third argument should select a block display from the view (my plan is to have one display per section, i.e Overview, Techspecs, Opinions ...).

Am I totally off track here..?

wow!!!

5

Thanx, useful!!!!!!!!!!!!!!!!

Thanks, this was just what I

5

Thanks, this was just what I needed.

Thanks

5

THank you very very much.. I had done this with USERNAME selected instead of USERID and I was pulling my hair! Saved the day..
you guys are awsome..

awesome

5

thankyou soooo much for this piece of awesomeness!! you are the best - but why cant it be obvious?

Cheers
Jeff

Great, but help!!

5

Thats great, but how can I use Views to select nodes authored by members of a particular organic group. I want to get all nodes in the site authored by the members of the given group, not just their group posts. The OG nid can be passed in through panels, but how do I get the members uids out and then the nodes they authored? Its driving me nuts, any help greatly appreciated.

You've already been

3

You've already been bookmarked, Drupal is a cms that has a lot to give but for that we need to be willing to research, not all the features are obvious but they can be found if you need them. Nevertheless Drupal web content management remains one of the best options at the moment and that's because it provides wide possibilities for the user.

Great Tutorial definitely

4

Great Tutorial definitely helpful to me!

Thanks this tutorial was just

5

Thanks this tutorial was just what I was looking for! Plus it was simple and to the point Thanks again

Drupal is a cms that has a

5

Drupal is a cms that has a lot to give but for that we need to be willing to research.

Thank you

5

Thank you for the informative article! Helped me a lot when I was doing our website! Well done! Thank you so much!

Edit: NonProfit removed link because highlighted site was not built with Drupal.

This is unique. It solved my

5

This is unique. It solved my issues immediately, and I must say that the documentation is first-rate (not always the case with Drupal modules).

STILL good instruction Nov. 30 2010, thanks

5

Great instruction, thanks for de-mystifying the strange labels and terms in the views admin UI.
I had got this to work through other tutorials, but was not sure how I did it.
your confirmation that the labels for things are very counter intuitive is very helpful. It is good to know that the thing works the way it seems to work rather than the way the descriptions would lead one to believe.

thanks!

and STILL good instruction...

5

as @donwinchell mentioned a year ago!

Awesome, really so simple yet so hidden, I would never have found the "Provide default argument" option if I hadn't found your article.

Thanks so much!