An example of a form with a select list of nodes with node count. This one also has the onchange attribute so it redirects the user on select. You do need to set up the Views view correctly for it to list by term id.
<form id="form-taxonomy-dropdown" method="post" action="/dir">
<?php
// get terms from vocab 1
$terms = taxonomy_get_tree(1);
$node_type = 'story';
$output = '<option value="">' . t('All Values') . '</option>';
foreach ($terms as $t) {
$count = taxonomy_term_count_nodes($t->tid, $node_type);
if ($count != 0) {
if (arg(1) == $t->tid) {
$selected = 'selected="selected"';
}
else {
$selected = '';
}
// only print value if there is a node connected
$output .= '<option value="' . $t->tid . '" ' . $selected . '>' . $t->name . ' (' . $count . ')</option>';
} // if count
} // foreach
if ($output) {
print '<select id="select-taxonomy-dropdown" onchange="top.location.href=\'/' . arg(0) .'/\'+document.getElementById(\'select-taxonomy-dropdown\').options[document.getElementById(\'select-taxonomy-dropdown\').selectedIndex].value">' . $output . '</select>';
}
?>
</form>
Comments
Post new comment