Here's working code for a "Recent Links" block. Since the links db schema doesn't have any date/time info, I just grab the most recently added rows to the links_links table. I also put the description info in the link "title" attribute so that it displays on mouse roll-overs.

This code is ready to be committed, but someone should probably add a configurable parameter: number of links to display

/**
* Implementation of hook_block().
*
* Generates a block with the most recent links.
*/
function linksdb_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Recent Links');
return $blocks;
}
else if ($op == 'view') {
$block['subject'] = t('Recent Links');
$block['content'] = theme('linksdb_block');
return $block;
}
}

function theme_linksdb_block() {
$result = db_query_range('SELECT name, description, url, id FROM {links_links} WHERE active = 1 ORDER BY id DESC', 0, 8);
while ($link = db_fetch_object($result)) {
$items[] = l($link->name, $link->url, array('title' => $link->description));
}
return theme('item_list', $items);
}

Comments

slimandslam’s picture

Might want to add this link:

$items[] = l('

', 'links',
null, null, null, null, true );
return theme('item_list', $items);
}

nancydru’s picture

Status: Needs work » Fixed

I will be providing a conversion function to the Web Links module, which already has this and much more.

nancydru’s picture

Status: Fixed » Closed (fixed)

A conversion function to the Web Links module is available for both 5.x and 6.x. That module provides this feature.