Experimenting with Views

Over the last weeks I have been doing a lot of experimenting with the new views module. I have actually been able to do some neat things with the headers like add an "A | B | C ..." to the heading to allow you to select on the nodes that begin with letter x, and allow a user to drill down on a list of terms.

But my latest has been I was able to turn a taxonomy into a set of tabs with only a single view. It actually works really well and is very good. Here is the code that does it.

[?php $views =& $GLOBALS['current_view'];
$args = $views->args;

$primary = taxonomy_get_tree(2, 0, -1, 1);
if ($args[0]) {
if (!($parents = taxonomy_get_parents($args[0]))) {
$parents[$args[0]] = taxonomy_get_term($args[0]);
}

$breadcrumbs = drupal_get_breadcrumb();
array_pop($breadcrumbs);
$breadcrumbs[] = l($items['items'][menu_get_active_item()]['title'], $view->url);

foreach ($parents as $term) {
$breadcrumbs[] = l($term->name, "{$view->url}/{$term->tid}");
}

drupal_set_breadcrumb($breadcrumbs);
}

if ($primary) {
echo '

    ';
    foreach ($primary as $term) {
    if ($parents[$term->tid]) {
    $primary_menu = $parents[$term->tid];
    }
    echo '
  • tid] ? ' class="active"' : '') .'>'. l($term->name, "{$view->url}/{$term->tid}", array('title' => $term->description)) .'
  • ';
    }
    echo '
';
}


if ($args[0] && ($children = taxonomy_get_children($primary_menu->tid))) {
echo '
    ';
    foreach ($children as $term) {
    echo '
  • tid == $args[0]) ? ' class="active"' : '') .'>'. l($term->name, "{$view->url}/{$term->tid}", array('title' => $term->description)) .'
  • ';
    }
    echo '
';
}
?]

It is not a real set of tabs like what the Drupal menu system creates, but it is the same <HTML> so it should always look the same as your standard tabs.

Also you need the argument handling code which will make sure that a second level term is always used.

[?php if (!$args || !$args[0]) {
$primary = taxonomy_get_tree(2, 0, -1, 1);
$term = array_shift($primary);

$args = array($term->tid);
}

return $args;
?]


my projects: 

Comments

You could probably put the

You could probably put the taxonomy description in the header too and retain that compared to your actual projects menu; you don't get the description until after clicking on the tab, but if you stick it in a div and style it to stand out I think it would look nice.

You might be able to skip a

You might be able to skip a lot of that poring into the global $menu object to figure out the view by checking global $current_view, which is an as-yet undocumented feature. It's actually a really recent addition.