The default Recent Comments view in Drupal 7 lays out comments in this fashion:
Essentially it’s an unordered list (ul) featuring a clickable title of the comment followed by a comma, then a timestamp.
But what if you want the comment to include the name of the author and the name of the node as well, and to rearrange it?
First, think of how you want the comment to look like and write it down. In the example below we are going to use in the following order:
- comment author followed by an
- @ sign, then the
- title of the node, a
- colon punctuation mark, followed by
- 96 characters of the comment (linked to the comment), then a
- timestamp with ‘ago’ appended.
Clone the ‘Recent Comments’ view in /admin/structure/views.
The default ‘Recent Comments’ only has the fields
‘Comment: Title’ and
‘Comment: Updated Date’.
We will add
‘(Content) Content: Title’
‘Global: Custom Text’
After some rearranging your fields should look like this:
- Click ‘Comment: ID’, then click ‘Exclude from Display’. Press Apply.
- Click ‘Comment: Title’ then click ‘Exclude from Display’. Press Apply.
- Click ‘Comment: Author’ then click ‘Exclude from Display’. Press Apply.
- Click ‘(Content) Content: Title’ then click ‘Exclude from Display’. Press Apply.
- Click ‘Comment: Updated date’ then click ‘Exclude from Display’. In the Date Format, choose ‘Time Span (with ‘ago / hence’ appended)’. Press Apply.
- Click ‘Comment: Comment’ then click ‘Exclude from Display’. Click ‘Rewrite Results’ and in the Link Path box, type ‘/comment/[cid]#comment-[cid]‘ like this:
Scroll down further and click ‘Trim this field to a maximum length’, and enter ’96’ at the Maximum Length box. Optionally, also click ‘Trim only on a word boundary’ and ‘Add an ellipsis’: Press Apply.
- Click ‘Global Custom text’, and enter the following in the ‘Text’ box ‘[name]@[title]:</br>[comment_body]</br>[timestamp]‘ like this:
Press Apply. The preview should now appear like this:
With some CSS styling you can come up with a snazzy looking sidebar comment list like this: