The S-Files: "A view that displays a user's content"
by Robert Douglass
UPDATE: I think this recipe is deprecated by the Views Attach module which addresses the use case directly: http://drupal.org/project/views_attach
Tech Support Case Studies
My duties at Acquia include answering the phone when European clients call needing support. Today I helped someone who needed a way for their site users to be able to find the content that they had authored. The recipe I suggested involves making a view that displays all content filtered by a particular user id. By having the view provide a block display you can then put that block on the user's profile page and they always have a place to go to find the latest content that they've created.
I provide an outline of the steps for this view below, but if you are in a hurry you can download the exported view and import it for yourself. You can also download a PDF file of all the screenshots I made while creating the view.
- Create a new view. The base table should be nodes.
- I modified the display to be HTML list values. I then added the title and type fields. The display and fields you choose, however, can be whatever you need. This is totally up to your needs.
- I added an argument. Arguments are bits of information that come in via the URL (path) which tell the view how to filter. In our case we want the view to filter on the user id, so we have to add a User: Uid argument.
- The trickiest part of this whole tutorial is how to configure the argument. See page 10 of the PDF for a screenshot. It is important that you choose the option "Action to take if argument is not present: Provide default argument." This is because we're creating a block view, and block views don't automatically take arguments from the URL like other views can. Thus we assume the argument is not present and provide it manually.
- Fortunately there is a complimentary option "Default argument type: User ID from URL." That is just what we need! Now the view will know that the integer present in the URL is to be interpreted as the user's id, and that it should use that number to filter the view.
- I then added a block display to the view, and saved the view. Don't forget to save the view!
- Now it's time to configure the block to appear on the user's profile pages.
- Viola! All done.
Acquia helps you succeed in building your websites by providing expert technical advice and support.