-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaxonomy_block.php
More file actions
39 lines (34 loc) · 1.1 KB
/
Copy pathtaxonomy_block.php
File metadata and controls
39 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* Show a a list of a palin taxonomy term with the count.
* It will not work for hierarchal taxonomy
*/
$vid = 4; //vocabulary id
$num_term = 20; //limit maximum terms
$parent = 0;
$max_depth = NULL;
/**
* Counts the number of nodes assigned to a term.
* @param integer $tid - term id
* @return integer $count - number of nodes
*/
function taxonomy_block_count_nodes_term2($tid) {
return db_select('taxonomy_index', 'ti')
->condition('tid', (int) $tid)
->countQuery()
->execute()
->fetchField();
}
$data = taxonomy_get_tree($vid, $parent, $max_depth);
$terms = array();
$items = array();
foreach ($data as $term) {
$terms[$term->tid] = $term;
$title = $term->name;
$title .= t(' (@count)', array('@count' => taxonomy_block_count_nodes_term2($term->tid)));
$item = l($title, 'taxonomy/term/' . $term->tid);
$items[] = $item;
//print taxonomy_block_count_nodes_term2( $term->tid );
}
return theme('item_list', array('items' => $items));
?>