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
Description

See my article at http://drupal.org/node/287#comment-87175

#1

he_who_shall_no... - January 26, 2006 - 06:16

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

he_who_shall_no... - January 31, 2006 - 07:08

This query works fine for me:

    $sql = 'SELECT DISTINCT
        nid,
        title,
        changed
      FROM
        {node} n
      WHERE
        status = 1
      ORDER BY
        changed desc
      LIMIT 0, 16';

#3

Zen - May 13, 2006 - 16:15
Version:4.6.5» x.y.z
Category:task» feature request

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

Zen - May 13, 2006 - 16:16
Status:active» needs work

And please submit it in patch form.

Thanks,
-K

#5

bdragon - June 23, 2007 - 20:26
Version:x.y.z» 6.x-dev
Status:needs work» active

#6

Yoda99 - July 28, 2008 - 21:48

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

 
 

Drupal is a registered trademark of Dries Buytaert.