Last updated March 26, 2011. Created by Chris Herberte on November 3, 2009.
Edited by linclark, GoddamnNoise, Quartz. Log in to edit this page.
There have been many support requests and forum topics about creating an index page with views although there seems to be little information on how to achieve it.
It is relatively simple when you know how, and using grid formatting and grouping we'll build an index page that will look sort of like this:
A
Node Title | Node Title | Node Title
B
Node Title | Node Title | Node Title
...The view export below will display all nodes in the above fashion. Once you have imported this view create a new php file in your current theme folder:
views-view-field--index--title.tpl.php (don't forget to clear cache)
<?php
print strtoupper($output[0]);
?>$view = new view;
$view->name = 'index';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '1',
'word_boundary' => 0,
'ellipsis' => 0,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 0,
'exclude' => 1,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
'override' => array(
'button' => 'Override',
),
),
'title_1' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title_1',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'created' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'time ago',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'created',
'table' => 'node',
'field' => 'created',
'relationship' => 'none',
),
'type' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 0,
'exclude' => 0,
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'name' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_user' => 1,
'overwrite_anonymous' => 0,
'anonymous_text' => '',
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'title' => array(
'order' => 'ASC',
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'Index');
$handler->override_option('items_per_page', 0);
$handler->override_option('style_plugin', 'grid');
$handler->override_option('style_options', array(
'grouping' => 'title',
'columns' => '4',
'alignment' => 'horizontal',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'views-index');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));Note: If the Devel Theme Developer module is enabled, your results will look similar to:
A
aardvark
A
anatomy
B
beach
B
bird
Disable the module and results will display correctly.
Comments
How does this work?
Could someone explain how this View is supposed to work? After importing and quickly reviewing the parameters I loaded
./views-indexin my browser and got this:Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/drupal/sites/all/modules/views/includes/handlers.inc on line 77An index browser which takes more than 30 seconds to process imho doesn't make much sense. Any suggestions how to build this more efficiently?
Thanks! -asb
Kefk | CineDat | Fotonexus | Encycan | Encymus | Taxidi
Can this views technique
Can this views technique achieve what the taxonomy_vtn module does for taxonomy terms?
--
Chalee
AZ filter using views
You can achiev similar functionality by creating a view with AZ filter (or you could alter that code). I wrote a post about this issue at my blog. Hope it helps.