Hello Folks,

I am using views to create a custom query, and would like to have the "add comment" appear after each item. How do I do this? Is there a "Add Comment" variable?

Thanks for any help.

Comments

darrenmothersele’s picture

I take it you are using a node View with fields.

Drupal comment links look like this: comment/reply/1#comment-form where 1 is the node ID for the node to add a comment to.

You can create this link by adding another field to your view, of type nid, then changing a couple of settings:

1) remove the title
2) select "rewrite the output of this field" and enter "Add comment" in the text area.
3) select "output this field as a link" and enter comment/reply/[nid]#comment-form in the Link Path field.

That should give you an add comment link on each item in your view.

adrianmak’s picture

Keep a note of this technique on future project.

jive01’s picture

wow, you just opened my eyes with the possibilities of this. Thanks!

@adrianmak : you're not kidding!

gcassie’s picture

This will work, but there's also a "Node: Add comment link" field available that should work out of the box. It is in the "Node" group of fields, not "Comment".

The field will also check if comments are enabled on the node in question and not display the link if they're not (but still display the label, if you have one).

Knowing how to rewrite field output is really handy in any case.

darrenmothersele’s picture

yes, better to use that - as it will take into account comment permissions and not display if commenting is not allowed for that node/user - I thought for some reason they didn't want to use that field.

MethodDan’s picture

Hi,

How would I modify this so the link just takes you to the comments list below the node and not the reply form? I've been looking for an anchor in the node page but can't seem to find the right one to just jump to the comments section.

Many thanks,

Dan

MethodDan’s picture

I seem to have fixed my own problem in the end, thanks anyway. I've rewritten the link output to go to the node page with #node_comments at the end. It just goes to the top of the page if no comments have been added yet. I'd like it to jump to the form if there's no comments but it's a start.

yskel’s picture

Just a note: it looks like this field outputs a blank value unless you've selected the option 'Display on separate page' under 'Location of comment submission form:' in the edit view for the content type you are working with. In my case, 'Display below post or comments' did not work. Obvious in hindsight, but too me a minute to figure out.

endupok’s picture

I ran into this problem, too, yskel, but I couldn't find the "Location of comment submission form" field in the Edit tab for the content type I was dealing with. Actually, that config field is not appearing on any of my (D7) content types. I used the NID work-around described above which was fine only because in this case I don't have the need to control commenting w/ permissions.

couturier’s picture

Thank you! I was not using a node view, but rather a table View with fields for a custom content type and could not get the Add Comment link to show up. After much searching, I found this post. The NID field with your instructions solved the problem. Thank you so much, darrenmothersele!

For more information, see the following posts:
Output field as a link
Plural comment counts

Vemma-1’s picture

Look great in the Preview area, but not in the content published on the Front Page. No teasers or anything are being used. Thx.

nourheine’s picture

i have the same problem as jive01, the only difference is that i want to add a link for the comment view of a specific product display, but i don't know how to create that view neither the link to it ,any help please.

seorusus’s picture

For Drupal 8 

1. Add a field Content:ID to the Top
Do it hidden.
2. Add a field Content:Type
Select "rewrite the output of this field" and enter "Add comment" in the text area.
3) Select "output this field as a link" and enter comment / reply / node / {{nid}} / field_comments in the Link Path field.

druapltech’s picture

Can you explain this link you mentioned comment / reply / node / {{nid}} / field_comments. I used this but it shows me access denied message. I am using nodeaccess module to restrict the user access.