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?
-HRose / Abalieno
On Mon, 18 Apr 2005 05:57:32 +0200, Abalieno abalieno@cesspit.net wrote:
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.
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
Well, I'm not sure but I thought that db_query() was deprecated, because it does not respect the 'node access'-api.. IMHO you should change 'db_query()' into 'db_rewrite_sql()'.. Se the documentation here: http://drupaldocs.org/api/head/function/db_rewrite_sql
Stefan
Op 18-apr-05 om 13:06 heeft Abalieno het volgende geschreven:
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
[ Drupal support list | http://lists.drupal.org/ ]
Stefan Nagtegaal wrote:
Well, I'm not sure but I thought that db_query() was deprecated, because it does not respect the 'node access'-api.. IMHO you should change 'db_query()' into 'db_rewrite_sql()'.. Se the documentation here: http://drupaldocs.org/api/head/function/db_rewrite_sql
Nearly, but not quite ;)
You should replace:
db_query($sql)
with:
db_query(db_rewrite_sql($sql));
Or somesuch.
P