By murph on
I am looking to try and achieve 3 things with the recent comments block:
1/ Have the node title displayed above each of the recent comments in the recent comments block.
2/ List (eg) 30 words of each comment
3/ Get rid of the time stamp
The code in the comments module that i think must be tweaked is this:
/**
* Implementation of hook_block().
*
* Generates a block with the most recent comments.
*/
function comment_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Recent comments');
return $blocks;
}
else if ($op == 'view' && user_access('access comments')) {
$result = db_query_range(db_rewrite_sql('SELECT c.nid, c.* FROM {comments} c WHERE c.status = 0 ORDER BY c.timestamp DESC', 'c'), 0, 10);
$items = array();
while ($comment = db_fetch_object($result)) {
$items[] = l($comment->subject, 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid) .'<br />'. t('%time ago', array('%time' => format_interval(time() - $comment->timestamp)));
}
$block['subject'] = t('Recent comments');
$block['content'] = theme('item_list', $items);
return $block;
}
}
From looking at the code above, would i need to add to the $result query to SELECT title FROM {node}? How would i actually code that in?
With the length of the recent comment itself, where can this be altered?
Presumabley i can just // everything after the <br/> (but of course inside the brackets) to get rid of the timestamp
Comments
ok so far...
I have got as far as adding the node title (pretty easy after using this that i found) and i have disabled the timestamp by commenting it out of the php.
Just left to do is find out where to change the length of the subject line that is created automatically (as no subjects are available to the user when adding the comment). I found this line in comment.module:
On looking up truncate_utf8 function, it looks like the 29 should be the limiter, however, when i set this to (eg) 100, the subject length stays the same in my recent comments block? Any ideas?
Doh!
Silly me, it had already stored the truncated subject line in the db...so it does work after all! :)
I just want to say I
I just want to say I followed your directions to remove the timestamp for the comment block of version 6.4 and it still works. THanks
No time in comment recent block, drupal 5
Yes, it also work on Drupal 5, just need to add //
in front of:
.'
'. t('@time ago', array('@time' => format_interval(time() - $comment->timestamp)))
BUT what are the lines to change to add the node titvle above the comment ?!
Thanks.
Replace $items[]... by these
Replace $items[]... by these three lines:
Genius
You're a genius !