Posted by molino on March 19, 2008 at 4:45pm
Jump to:
| Project: | List Nodes by Vocabulary |
| Version: | 5.x-1.0 |
| Component: | User interface |
| Category: | support request |
| Priority: | normal |
| Assigned: | NancyDru |
| Status: | postponed |
Issue Summary
create a block of this
Comments
#1
molino, you mean list all nodes within vocabulary in one block?
#2
This is actually for Drupal 6, but should be real close for 5.
/**
* Implements hook_block().
*/
function vocabulary_list_nodes_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
return vocabulary_list_nodes_block_info();
case 'view':
return vocabulary_list_nodes_block_view($delta);
case 'configure':
return vocabulary_list_nodes_block_configure($delta);
case 'save':
return vocabulary_list_nodes_block_save($delta, $edit);
}
}
function vocabulary_list_nodes_block_info() {
return array(
0 => array(
'info' => t('Vocabulary list nodes'),
'cache' => BLOCK_NO_CACHE,
),
);
}
function vocabulary_list_nodes_block_view($delta = 0) {
$items = $block = array();
switch ($delta) {
case 0:
$vocs = variable_get('vocabulary_list_nodes_block_vocs', 0);
$limit = variable_get('vocabulary_list_nodes_block_limit', 10);
$vocabulary = taxonomy_vocabulary_load($vocs);
$block['subject'] = $vocabulary->name;
$terms = array_map('_taxonomy_get_tid_from_term', taxonomy_get_tree($vocabulary->vid));
$sql = 'SELECT DISTINCT(n.nid), n.title, n.sticky, n.created FROM {node} n '
. 'INNER JOIN {term_node} tn ON tn.vid=n.vid '
. 'WHERE tn.tid IN (' . db_placeholders($terms) . ') '
. 'ORDER BY n.sticky DESC, n.created DESC';
$result = db_query_range(db_rewrite_sql($sql), $terms, 0, $limit);
while ($node = db_fetch_object($result)) {
$items[] = l($node->title, "node/$node->nid");
}
$block['content'] = theme('item_list', $items, NULL, 'ul',
array('class' => "vocabulary-list-nodes vocabulary-list-nodes-$vocabulary->vid"));
break;
}
return $block;
}
function vocabulary_list_nodes_block_configure($delta = 0) {
$voc_list = $form = array();
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $vid => $vocabulary) {
$voc_list[$vid] = $vocabulary->name;
}
switch ($delta) {
case 0:
$form['vocabulary_list_nodes'] = array(
'#title' => t('Vocabulary list nodes'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['vocabulary_list_nodes']['vocs'] = array(
'#title' => t('Which vocabulries to show'),
'#type' => 'radios',
'#options' => $voc_list,
'#default_value' => variable_get('vocabulary_list_nodes_block_vocs', 0),
'#attributes' => array('class' => 'container-inline'),
);
$form['vocabulary_list_nodes']['limit'] = array(
'#title' => t('How many items to show'),
'#type' => 'textfield',
'#size' => 8,
'#default_value' => variable_get('vocabulary_list_nodes_block_limit', variable_get('feed_default_items', 10)),
);
break;
}
return $form;
}
function vocabulary_list_nodes_block_save($delta = 0, $edit = array()) {
dsm(print_r($edit, true));
variable_set('vocabulary_list_nodes_block_vocs', $edit['vocs']);
variable_set('vocabulary_list_nodes_block_limit', $edit['limit']);
}
This is part of my port to Drupal 6 #243724: Drupal 6 Port - List Nodes by Vocabulary.
#3
#4
This is now part of the 6.x-1.x-dev version. If someone wants to backport it, please supply a patch.