[drupal-support] Re: drupal 4.6.0 - missing categories block?

Abalieno abalieno at cesspit.net
Mon Apr 18 11:06:41 UTC 2005


>> I'm upgrading to the new version but it seems that the categories block 
>> I was using is now gone.
>>
>> There's a way to have it back?
>
> If you only want to show one node type, try http://drupal.org/node/20260.

Thank you, I did a bit of a mess between the new and previous code. Here's 
the result:

/**
* Implementation of hook_block().
*
* Generates a block with all categories.
*/
function taxonomy_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Categories');
return $blocks;
}
else if (user_access('access content')) {
$result = db_query("SELECT term_data.tid, term_data.name, MAX(created) AS 
updated, COUNT(*) AS count FROM {vocabulary_node_types} INNER JOIN 
{term_data} USING (vid) INNER JOIN {term_node} USING (tid) INNER JOIN {node} 
USING (nid) WHERE node.status = 1 AND vocabulary_node_types.type = 'story' 
GROUP BY term_data.tid, term_data.name ORDER BY updated DESC, 
term_data.name");
$items = array();
while ($category = db_fetch_object($result)) {
$items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. 
$category->tid) .'<br />'. t('%time ago', array('%time' => 
format_interval(time() - $category->updated)));
}
$block['subject'] = t('Categories');
$block['content'] = theme('item_list', $items);
return $block;
}
}

This makes the categories modules work as before (so listing even the last 
update to each), plus it fixes the problem of forum categories showing in 
the block.

The block works perfectly in my site but can someone check quickly the code 
to see if it's heavy or badly written?

-HRose / Abalieno 




More information about the drupal-support mailing list