By Grantovich on
How do I create a view that provides a block, which contains a list of content filtered by the author of the page that the block is being displayed on? Or if this is not possible with blocks, how can I achieve the same results through other means? The block will never be displayed on anything other than the full page view of a node, so I don't need to worry about what happens outside of those circumstances. Also, I'm using the pathauto module so unfortunately there are no meaningful URL arguments to grab.
Comments
Addendum
I've just found the Views Argument API module, which appears to do exactly what I want, right out of the box. But I can't even get it working! I keep getting database errors all over the place, both during installation and when I try to modify a view. Sometimes I get it to enable with no errors, but when I turn on the argument handler, it inexplicably fails to work, and the view falls back to "no results" mode. I can't even figure out which version to use; 1.2 was updated more recently, but update_status gives a severe warning that 1.0 is the "recommended" version. I've gotten errors and failing-to-work with both versions. Is this module compatible with URL aliases? Has anyone ever gotten it to work properly with the node author feature?
Probably only need the view module
Unless something has changed in a more recent version, the views module has all the functionality you would need. It supports arguments, and author id is one of the default variables you can pass as an argument - %author. I usually use a combination of CCK + views + viewfield to accomplish this.
I create a view with whatever filters I want to use. Then, I add an argument - in your case User: UID is Author.
Then, I create a view field in whatever content type I wish to display the view in. I set the view to whatever I named my new view, and give it an argument of %author.
I'm not sure how you'd do it in a block since arguments are passed through the URL; you'd probably have to use argument handling code.
------------------------------
http://fraggles.artsci.wustl.edu (Drupal user documentation and development blog)
Viewfield
I had looked at the Viewfield module just recently, but the description didn't mention anything about being able to pass arguments like that. If it works how you describe, I wouldn't need to use a block, and the argument problem solves itself. I'll try installing Viewfield and let you know how it went.
Yay viewfield... but a problem
Thank you! Viewfield works exactly as you said, and I am now able to create a "posts by this user" block on content types I choose. But there is one catch, and it's a doozy: Now when my users go to submit a content type that includes this feature, they are presented with the interface to change the view that gets displayed! I just want to set a default value and hide all the details from the users, so the block magically shows up on its own and there are no unfamiliar inputs in the submission form. I tried CCK Field Permissions, but you can't hide the form elements without also throwing away the default values! Is there any way to fix this?
One possibility -
You might put the field in a group by itself and set that group to 'collapsed'. If you really don't want them to see it, you could also use CSS to hide that element on the admin side since each element has a unique class. For example, if you have a group called 'All Day' the class would be 'group-all-day'. To hide it, just add something like:
To your theme CSS. You'll need to be careful if you're trying to display that fieldset to visitors however... I don't run into this problem because I'm using custom templates for each content type in my theme anyway.
------------------------------
http://fraggles.artsci.wustl.edu (Drupal user documentation and development blog)
Thanks
This looks like it will be a perfectly acceptable workaround until CCK Field Permissions is fixed (the not-keeping-defaults thing is listed as a critical issue so I assume it will be worked on at some point).