Hi everybody,
I'm trying to determine the best method to create a 3 column list of vocabulary terms similar to what you would find at most directory based sites.
I'm doing a site with localized content and need to display a list of US states (the terms), that would link to a page containing a list of teaser nodes.
I've created the teaser pages using views and have tried the Views bonus pack (3 column by term) to create the directory layout but have not had any success.
Thanks for any advice,
Rob

Comments

nancydru’s picture

Let me do some small changes to my usual vocabulary list code. This is not difficult; it just takes a bit of additional CSS. I don't see any need for Views in any of what you're asking. A teaser list is normal "taxonomy/term/xxx" presentation.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

robertem’s picture

Thanks Nancy, I would appreciate any help you could give.
Rob

nancydru’s picture

Put this code in a php-format page.

<?php
  $vid = 2; /* <---- put correct vocabulary ID here */
  $items = array();
  $terms = taxonomy_get_tree($vid);
  print '<div class="state-block">';
  foreach ( $terms as $term ) {
    $count = taxonomy_term_count_nodes($term->tid);
    if ($count) { /* don't show terms with 0 count */
      print '<div class="state-list">' . l($term->name,'taxonomy/term/'.$term->tid)." (".$count.") - ".$term->description . '</div>';
    }
  } /* end foreach */
?>

Then include this in your CSS:

.state-block {width:100%; position: relative; clear: both;}
.state-list {width: 31%; position: relative; float: left;}

This is untested, but should work.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

robertem’s picture

This worked perfectly, thanks so much!
Rob

designwork’s picture

You cane use the view bonus with panles.module or more custom...

A new function for the view grid module. A three column grid_view put after the normal function theme_views_bonus_view_grid a new one.

//16.5.07 Grid View Taxonomy-Terms will sort everything by taxonomy terms and print them sorted by term.
function theme_views_bonus_view_grid_ext($view, $nodes, $type) {
drupal_add_css(drupal_get_path('module', 'views_bonus') .'/views_bonus.css');
$fields = _views_get_fields();
$content = '

name . '">';
$count = 0;
$total = count($nodes);
$myterm_prev = "";
foreach ($nodes as $node) {
if (isset ($node->term_data_name)){
$myterm = $node->term_data_name;
} else {
$myterm = t('No term');
}
//
$item = '';
if ($count == 0) {
$content .= '
';
} elseif ($count % 3 == 0 || $myterm != $myterm_prev) {
if ($myterm != $myterm_prev) {
$content .= '
';
} $content .= '';
}

foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
if ($field['label']) {
$item .= "

" . $field['label'] . "

";
}
$item .= "

" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view) . "

";
}
}
$content .= "

\n";

$count++;
//if ($count % 4 == 0 || $count == $total) {
if ($count == $total) {
$content .= '

';
}

$myterm_prev = $myterm;
}
$content .= '

'.$myterm. '
'.$myterm. '
name'>$item

';

if ($content) {
return $content;
}
}

Than put this in code:

$items['bonus_grid_ext'] = array(
'name' => t('Bonus: 3 Colum Grid View by taxonomy term'),
'theme' => 'views_bonus_view_grid_ext',
'validate' => 'views_ui_plugin_validate_list',
'needs_fields' => true,
);

the function views_bonus_views_style_plugins
Now you can chose your new view in the views Module

Dirk

robertem’s picture

Thanks Dirk, I'll give this a try as well. Always good to have options!
Rob

robertem’s picture

It looks as though I may have to go with Views after all as I will need to have some control over the sort order on the summary pages.
I'm having a few issues with your code however.
Should this line $content = 'name . '">'; be $content = '"'.name . '">'; ?
Also, what configuration should I be using in Views?
I was trying different options using "Taxonomy: Vocabulary Name".
Thanks again,
Rob

designwork’s picture

Hi Robertem,

I´m trying to understand, its hard not to see what you need.
1. Your Vocbulary is USA.
2. Your terms are 51 States right?

Ok lets start.

1. First generate a new View as Page with a URL, Title etc..

2. Chose the new grid View I gave to you.

3. Chose the fields you want to display in your View. First I would take Node Title with the option "as link".
(that will bring you to the node)

4. Chose your Filter it should be Taxonomy Vocabulary (USA) and the option "one of" (all 51 States)

So i hope this will help you.
Anyway just contact me or give me access to a testing page where I can have a look.

Dirk

robertem’s picture

Thanks Dirk,
That's what I was thinking regarding views, just wanted to be sure I understood.
I'm getting a syntax error in the code you gave me on this line;
$content = 'name . '">';

in the original grid bonus the line is
$content = '

name . '">';

should it be
$content = 'name . '">';

Thanks,
Rob

robertem’s picture

Could you repost your code inside a code tag? some of the html is getting striped out

This

$content = 'name . '">';

in the original grid bonus the line is 
$content = '<table class="view-grid view-grid-' . $view->name . '">'; 

should it be 
$content = '<class="' . $view->name . '">'; 

is coming out as
$content = 'name . '">';

in the original grid bonus the line is
$content = '

name . '">';

should it be
$content = 'name . '">';

Thanks,
Rob

designwork’s picture

Hi Rob,

its working now? I think it´s a copy and paste problem. Still any questions?

Dirk

robertem’s picture

Hey Dirk,
Still the same issue, you just have to surround the whole block of code with code tags (see below under "allowed html tags") so the Drupal forum won't strip the tags out.
Thanks again

designwork’s picture

Lets see if we understand right,

First just have a look here http://www.freelens.ws/dirksway/user/1/galerie or here for three collums http://www.freelens.ws/dirksway/user/16/galerie

Its a testing side but you can see the new grid view in action. You want change the general layout for a taxonomy vocabulary? Or a different Style of a View (MYSQL-list)? Any testing site for me to see?

Or something like the front page of the actual page we are doing? www.freelens.ws/dirksway
Here Im using views as well ........

But anyway if you tell me an email e send you the new views_bonus.module

Cheers Dirk

ctmann’s picture

If I understand you correctly, you're saying to paste the code which begins...

"//16.5.07 Grid View Taxonomy-Terms will sort everything by taxonomy terms and print them sorted by term.
function theme_views_bonus_view_grid_ext($view, $nodes, $type) {
drupal_add_css(drupal_get_path('module', 'views_bonus') .'/views_bonus.css');"

anywhere in the "views_bonus_grid.module"....

I've done that.

But then you write, "Then you put this in code..."

$items['bonus_grid_ext'] = array(
'name' => t('Bonus: 3 Colum Grid View by taxonomy term'),
'theme' => 'views_bonus_view_grid_ext',
'validate' => 'views_ui_plugin_validate_list',
'needs_fields' => true,
);

I have no idea how to use this final code snippet. Where do I paste it? Into which module or file? What does "put it in code" mean? Please help...

Many Thanks!

designwork’s picture

Hi ctman,

wich version of the view_bonus_module are you using? I will send you the module with the new function if you send me an email!

Dirk