This theme override will create a taxonomy listing like this:

Restaurants (10)
Pizza (2), Oriental (1), Fast Food (3), Seafood (4)

Required modules: Views, Views_Bonus, Panels
Limitations: Only tested with a 2 level taxonomy hierarchy. Will override the theming of all views of this type.

With the above modules, you get a view called panels_by_term. Normally, this lists the taxonomy terms in tables in three columns. This override will still put them in 3 columns but with the look of the example above.

Simply add this to your template.php file. You don't need the opening and closing php tags if you already have stuff in that file. They are there to trigger the syntax highlighting.

// Override the panels by term theming
function phptemplate_views_bonus_panels_byterm_summary($view) {
  drupal_add_css(drupal_get_path('module', 'views_bonus') .'/views_bonus.css');
  // argument 0 must be a vocabulary ID
  $vid = $view->args[0];
  $tree = taxonomy_get_tree($vid);
  // group terms with their parent
  foreach ($tree as $term) {
    $cnt = taxonomy_term_count_nodes($term->tid);
    if ($term->depth > 1) {
      $prefix = str_repeat('--', $term->depth-1). ' ';
    }
    $txt = array($prefix. l($term->name, "$view->real_url/$term->tid"). " ($cnt)"); 
    if ($term->depth == 0) {
      $parent_tid = $term->tid;
      $groups[$parent_tid]['header'] = $txt;
    }
    else {
      $groups[$parent_tid]['rows'][] = $txt;
    }
  }
  
  // render the groups into tables spread across 3 columns
  $content = array();
  $i=0;
  foreach ($groups as $group) {
    switch ($i % 3) {
      case 0:
        $section = 'left';
        break;
      case 1:
        $section = 'middle';
        break;
      case 2:
        $section = 'right';
        break;
    }

// BEGIN MODIFIED SECTION

    $subterms = array();
    if (is_array($group['rows'])) {
      foreach ($group['rows'] as $subterm) {
              array_push($subterms, $subterm[0]);
            }
    }
    
    $content[$section] .=  '<div style="display:block;"><b>' . $group['header'][0] . "</b><br />" . implode(", ", $subterms) . "</div>";
    
// END MODIFIED SECTION

    $i++;
  }  
  return panels_print_layout('threecol_33_34_33', $content);
}

You'll likely want to give your div an ID and style it in your style.css instead. I just put the style in there to keep this snippit simple.

Comments

anandcte13’s picture

I used above codes by adding in my template.php file but I am unable to use these codes.

How to use

dddave’s picture

This is a snippet for Views version 1 which you most likely are not using. Search for theming information relevant to your version of Views which most likely is going to be v3.