When using views under fields options (I'm creating a block) I have the options of 'Comment: Comment', 'Comment: Comment: Author Name' etc.

This is useful for creating a block updating visitors of recent commentary on the site (e.g. I have a block in a nicely formatted list "XXX replied to the topic YYY (NODE TYPE) started by ZZZ" where XXX is the author of the latest comment and ZZZ is the ZZZ is the author of the original node.

I'd really like to put more of a human face on this commentary block. It is possible to use 'Node: Author Picture' as another of the options in the available views fields, but I'd really like, relevant to who's making to commentary, to use 'Comment: Author Picture' - yet this field is not available.

Does anyone have experience or knowledge of adding a field 'Comment: Author Picture' as a field in a block in Views? I'm stumped.

Comments

timmeh’s picture

i would really like to know how to do this too. anyone have any idea??

vm’s picture

If either you aren't using the advanced help.module consider checking it out. It comes with a good deal of documentation for views.

I can't help with specific with views 1 as I didn't come to terms with views until views 2 was released for Drupal 6.x which allows you much more flexibility where data is being pulled from.

views 1 only worked with what was in the node table if I understand correctly. views 2 works through all kinds of tables.

timmeh’s picture

i am using views 2 in drupal 6.6 as well.

as for getting the last comment authors pic to be in the view, maybe use the "relationship" function? i do use advanced help but it only is taking me so far. any ideas would be appreciated.

WorldFallz’s picture

From what I could see, you don't need a relationship. When making a comment view the "Comment: Author" field is available. You just need to theme it to show the picture. If you click on the "Theme: information" link in the basic settings box, it will give you the tpl file names for theming the view. You want to theme the author name field. There's some good info about theming views in the advanced help.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

timmeh’s picture

thanks for you reply.
since i've read this, i've tried to get my feet wet. i'm a neophyte php coder (although i dont think this task will require much coding).

i've read the advanced help about 20 times along with googling 'themeing a view' in drupal with little luck.

i think i understand the basic concept of what to do here:
theme the "author name field" so it shows a picture.

i'm just have no idea where to start.

in Views 2, in the 'theme' folder there's a bunch of tpl.php files which i think i'm suppose to add some code to or perhaps create a new tpl.php file in this folder.

do you have anymore hints? perhaps some links to a thread that discusses this??

thanks.

WorldFallz’s picture

I just looked at this on my dev site. Actually-- if you do add the uid relationship, the user picture field becomes available in the fields list and you don't have to theme it in. That's the easiest way.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

timmeh’s picture

hmmm...i see the user picture field, but it's for the original poster of the node. i'm not sure how u are getting this.
do u think you could walk through the steps in how you did this to be able to create a view with the last comment authors pic to show?

WorldFallz’s picture

Sure it's easy. Create a comment view, add the 'Comment: User' relationship, then go to the list of fields, and select the 'Users' group-- the 'User: Picture' field will be one of the available options.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

timmeh’s picture

still doesn't work. a relationship between "comment: user" and "user: picture" links to the original authors picture. there would have to be a relationship between "Node: Last comment author" and "user: picture" i would assume, which i do not get that option for.

i'm now just getting 2 views with the originals authors picture. or am i doing something different from what you are doing??

WorldFallz’s picture

a relationship between "comment: user" and "user: picture" links to the original authors picture.

Not in my test view-- it's working exactly as expected (showing the comment author's picture, not the node author's picture). Adding the relationship is exactly what allows the comment's author to be linked to it's user table info. That's the entire point.

I'm not sure what else to tell you. Here's an export of the view:

$view = new view;
$view->name = 'comments_w_pics';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'comments';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'uid' => array(
    'label' => 'User',
    'required' => 0,
    'id' => 'uid',
    'table' => 'comments',
    'field' => 'uid',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'name' => array(
    'label' => 'Author',
    'link_to_user' => 1,
    'exclude' => 0,
    'id' => 'name',
    'table' => 'comments',
    'field' => 'name',
    'relationship' => 'none',
  ),
  'timestamp' => array(
    'label' => 'Post date',
    'date_format' => 'small',
    'custom_date_format' => '',
    'exclude' => 0,
    'id' => 'timestamp',
    'table' => 'comments',
    'field' => 'timestamp',
    'relationship' => 'none',
  ),
  'subject' => array(
    'label' => 'Title',
    'link_to_comment' => 1,
    'exclude' => 0,
    'id' => 'subject',
    'table' => 'comments',
    'field' => 'subject',
    'relationship' => 'none',
  ),
  'picture' => array(
    'label' => 'Picture',
    'exclude' => 0,
    'id' => 'picture',
    'table' => 'users',
    'field' => 'picture',
    'relationship' => 'uid',
  ),
));
$handler->override_option('sorts', array(
  'timestamp' => array(
    'order' => 'DESC',
    'granularity' => 'day',
    'id' => 'timestamp',
    'table' => 'comments',
    'field' => 'timestamp',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'recent-comments');
$handler->override_option('menu', array(
  'type' => 'normal',
  'title' => 'Recent Comments w Pic',
  'weight' => '0',
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

IWasBornToWin’s picture

In order to get user photo to show I selected "node" when adding the "Comment:user" relationship. Then you can go back and edit the User:Picture field that you added and it will give you an option of linking the picture to the Node or the User.

IWasBornToWin.com
Knock'em alive!
James

Witch’s picture

This realy works. I use it for a forum block but now i have duplicate forum topics in this block. how can i avoid duplicate topics in this block?

mr.alinaki’s picture

Thanks! This work.

baff’s picture

The views relation comment gives you the first comment author picture, not the last one, which is the issue of this thread. I did not get it working showing the last comment author picture.

thomas1977’s picture

I was having trouble with this issue as well - exactly as you describe, baff. Solution: in the comments view simply remove the relationship "Comment: node" (you still need the relationship "Comment: user"). And there you go. Works like a charm.

fadgadget’s picture

Does anyone know how to get this working in a node view not a comment view? thanks. Ive tried adding every relationship available to me but with little success. I just want to show the image of the last commentator on a node in a node view.