When displaying recent comments from all users I wanted to display the corresponding users picture with their comment. Using the "User: Author Picture" filter always returns the same picture (for user id 1).
Here's my view:
$view = new stdClass();
$view->name = 'comments_recent';
$view->description = 'Display recent comments block';
$view->access = array (
);
$view->view_args_php = '';
$view->page = FALSE;
$view->page_title = '';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'node';
$view->url = '';
$view->use_pager = FALSE;
$view->nodes_per_page = '0';
$view->block = TRUE;
$view->block_title = 'In the blogs...';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'list';
$view->nodes_per_block = '3';
$view->block_more = TRUE;
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
array (
'tablename' => 'comments',
'field' => 'timestamp',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'users',
'field' => 'uid',
'label' => '',
),
array (
'tablename' => 'comments',
'field' => 'name',
'label' => '',
),
array (
'tablename' => 'comments',
'field' => 'subject',
'label' => '',
'handler' => 'views_handler_field_commentlink',
'options' => 'link',
),
array (
'tablename' => 'comments',
'field' => 'comment',
'label' => '',
),
);
$view->filter = array (
array (
'tablename' => 'node_comment_statistics',
'field' => 'comment_count',
'operator' => '>=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'comments',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '0',
),
);
$view->exposed_filter = array (
);
$view->requires = array(comments, users, node_comment_statistics);
$views[$view->name] = $view;
Comments
Comment #1
merlinofchaos commentedThe 'user' fields here will always link to the author of the node the comment is on, not the comment itself.
Comment #2
defunctcitizen commentedany advice as to how would one go about displaying the comment author's picture instead of the node author's picture? i'm stuck...
Comment #3
chrispooh commentedI'm searching for the solution, too. Please help.
ciao - chrispooh
Comment #4
merlinofchaos commentedAt the moment, I don't think Views has a field handler to accomplish this.
Comment #5
dorien commentedSame question... I'm looking to make a "featured user" block, but seem stuck...
Comment #6
gkkg commentedHi,
I had the same problem. What I did:
1) Create a view which contains the CID (Comment ID).
2) Use the views theming wizard to create the following files:
=> views-list-viewname.tpl.php
=> views-list-viewname.css
=> add function phptemplate_views_view_list_viewname($view, $nodes, $type) { ... } to template.php
3) In views-list-viewname.tpl.php I added the following code:
This code looks up the user id for a given comment id and then looks for the picture for the found user. The picture is a path relative to the base_path => so put everything together, and you're done.
At least it works for me :-)
Comment #7
Gabriel R. commentedI'll give this a try too.
Comment #8
kabarca commentedI know this is an old post but since it is not resolved then I will provide it :)
(D7)
1. While in the view, add a relationship that contains the "comment: author"
2. Add a new field "User: Picture" and while editing select the "author" from the relationship drop down.
That is all it takes.