Add a "Recent posts" block to the tracker module
he_who_shall_no... - January 26, 2006 - 05:18
| Project: | Drupal |
| Version: | 6.x-dev |
| Component: | tracker.module |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
See my article at http://drupal.org/node/287#comment-87175

#1
Used the query (unmodified) from the tracker module and added the hook_block function to it. It can be inserted in the tracker.module.
/**
* Implementation of hook_block().
*/
function tracker_block($op = 'list', $delta = 0) {
global $user;
if ($op == 'list') {
$blocks[0]['info'] = t('Recent posts');
return $blocks;
}
else if ($op == 'view') {
$sql = 'SELECT DISTINCT
(n.nid),
n.title,
n.type,
n.changed,
n.uid,
u.name,
l.last_comment_timestamp as last_post,
l.comment_count
FROM
{node} n
INNER JOIN {users} u on n.uid = u.uid
INNER JOIN {node_comment_statistics} l on n.nid = l.nid
WHERE
n.status = 1
ORDER BY
last_post desc
LIMIT 0, 16';
$sql = db_rewrite_sql($sql);
$result = db_query($sql);
$rows = array();
while ($node = db_fetch_object($result)) {
$rows[] = l($node->title, "node/$node->nid");
}
$block['content'] = theme_item_list($rows);
$block['subject'] = t('Recent posts');
return $block;
}
}
#2
This query works fine for me:
$sql = 'SELECT DISTINCTnid,
title,
changed
FROM
{node} n
WHERE
status = 1
ORDER BY
changed desc
LIMIT 0, 16';
#3
Can you please:
a) make this more generic? i.e. give the admin choice to choose the node-types, number of entries etc.?
b) also add a recent comments block? (with similar choices)
We can then get rid of the two blocks in the forum module.
Thanks,
-K
#4
And please submit it in patch form.
Thanks,
-K
#5
#6
The block works fine with the top snippet added but when a user comments on an article it makes that article jump back to the top of the list. I would like user comments not to be taken into account and only the publication date.
I am clueless as to what to remove from the snippet.
Regards
Sven