Experimenting with Views

Posted by gordon on Tue, 18/04/2006 - 4:27pm

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;
?]



Depositos Depositos

Depositos
Depositos Bancarios
Deposito Gasol
Comparativa Plazo Fijo
Depositos Intereses
Depositos Bankia
Bolsa
Cotizacion Bankia
Horoscopo
Horoscopo 2012
Prestamos
Mejores Prestamos
Creditos
Mejores Creditos
Bancos
Cuentas Corrientes
Cuentas Remuneradas
Productos Financieros
Previsión Euribor 2012
Mejores Depositos
Mejores Depositos 2012
Mejores Depositos 2013
Mejores Depositos Bancarios
Pymes
Pyme
Cursos
Cuentas Rentables
Calendario Laboral 2012
Calendario 2012
Calendario 2013
Hipotecas
Depositos alta rentabilidad
Ahorrar Dinero
Ahorrar
Cuentas Remuneradas
Mejores Cuentas Remuneradas
Depositos
Cuentas Corrientes
Renta 2012
Renta 2013
Tarjetas de Credito
Seguros
Planes y Pensiones
Planes de Pensiones
Cambio euro dolar
Euro dolar
Buscar Trabajo
Buscar Empleo
IPC
IPC 2012
Dinero
Regalos Nominas
Fondos de inversion
Tier 1
Paro
Tasa de Paro
Comparador Seguros
Transferencias Bancarias
Entrevista de trabajo
Mejores Ofertas Bancarias
Mejores Depositos Bancarios
que es cuenta
Ayudas al Alquiler
Ayudas al alquiler para jovenes 210 euros
Empresas en Crisis
Cuenta Internet
Cuentas Nomina
Cuentas Alto Rendimiento
Ejecuciones Hipotecarias
Rating Bancos
IG CFD
Agencias de Rating
UTE
Laudo Arbitral
Productos Empresas
Tipos de Sociedades
Vender en Internet
Comparativa Plazo Fijo
Calculadora de paro
Cobrar el Paro
Enero 2012
Fiscalidad seguros
Fiscalidad seguro de vida
Licencias apertura
Como cotejar documentos
Contratos para autónomos
Tipos Impuesto de Sociedades
Fotocopia cotejada
Coeficiente de Gini
EUR USD
USD EUR
IRPF 2012
Domiciliar Nomina
Gastos deducibles autonomos
Comprar sociedad
Seguridad Social autonomos
Gastos Hipoteca
Impuestos Hipoteca
Revision hipoteca
Desgravar hipoteca
Deduccion vivienda
Tipos Impuestos

sikiş

Please consider submitting

Please consider submitting this as a patch to views module. This is incredibly useful stuff.

Basically by published this

Basically by published this here, which is pushed through to drupal planet. I am not sure how I can do much more than what I have already done. It is not like it is a module or source code that can be committed. It is just some code which can be cut and pasted into a view.

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.

Thanks.

I have changed to views to use the new global var to find the view.

example

a demo url would be real nice. sounds cool.

-moshe 

demo

I have done this a yet to be released client site, So I have set up a demo here.

Goto /myprojects_menu


Wow, that's pretty freakin'

Wow, that's pretty freakin' cool. Of course, I immediately spot what seems like a Views bug in the breadcrumb, so I guess I have to look into that.

Thanks, I really like the

Thanks, I really like the views module. You can just do so much. I am actually thinking of using this as my projects menu permantly

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.