This is a follow up question to http://stackoverflow.com/questions/3880679/drupal-views-exposed-filter-of-author-name. The following question was answered and works. I can filter a view by user name. The user name is entered is entered by typing in a box and the box then auto completes. Rather then doing this I would like the list of users as a drop down. I only need one user to be selected. Do you know if this is possible?
Yes, this is possible. Its not particularly tough to do this... but its slightly tedious. You need to create two views
- The first view is a list of users on your system (a View of type
Users
). This user list is displayed as a dropdown instead of a list (using jump menu view style). Clicking on any user within this dropdown will call the second view with the uid (user id) of the selected user as the argument in the URL. This view is a block. - The second view is a simple Node listing. It is a page view at a particular URL. It takes 1 argument which is the uid (user id) of the user.
Detailed Steps
- Download the Ctools module http://drupal.org/project/ctools Enable the Chaos Tools Module. This module provides a Views Style Plugin called "Jump Menu"
- Create a new view of type
Users
and NOT typeNode
which you usually create. In the fields addUser: Name
andUser: uid
. For the settings ofUser: uid
, make sure you click onRewrite the output of the field
. The rewritten output of the field should bemy_node_list/[uid]
. Make sure you select theexclude from display
checkbox. - In the settings for
Style
in the view, select theJump Menu
style. Click on the settings for the style. Make sure thePath
dropdown hasUser: uid
choosen - Add a block display to the view. Name the block
User Drop Down
- Save the view
- Add the block
User Drop Down
to any region in your theme e.g. Content Top (usually the best) or left sidebar. Make sure the block is only visible at the urlsmy_node_list/*
andmy_node_list
by setting the block visibility settings - Now create another view of type
Node
. Add an argument fieldUser: uid
. Add the fields you are interested in e.g.Node: title
,User: Name
etc. - Add a page display. Let the page be at the url
my_node_list
- Save the view. Test the dropdown with its list of users on the system at
http://yoursitename/my_node_list
Hello:
Thanks for the tutorial. I have it working with just one glitch. When I select a user from the jump menu located at my_node_list, I'm redirected to the list of nodes for the user located at my_node_list/1. However, when I select another user from the jump menu at my_node_list/1, I'm redirected to the default list of all nodes because the URL becomes my_node_list/my_node_list/2. If I select a another user from the jump list at my_node_list/my_node_list/2, I'm redirected to the default listing of all nodes again with a URL of (you guessed it) my_node_list/my_node_list/my_node_list/3.
So, essentially, the jump list works just great from the initial view at my_node_list but appends a second, third, fourth "my_node_list" to the URL from subsequent pages.
Any idea of how to fix this?
Thanks,
Patricia