Drupal Articles » Drupal case study on how this site was created » Views import code for the Music page and Recent Projects block
The following is code which you can import into Views 2 (Drupal 6 only) in order to recreate the view used for the Music page of this site, as well as the Recent Projects block on the Home page. To import this, go to Administer > Site building > Views > Import (admin/build/views/import).
A Nodequeue is used in this View (my Nodequeue is named music-film), so you should have Nodequeue installed when importing this View. If you don't want to use Nodequeue, you can change the sorting options to submission date or some other criteria after the View has imported successfully, and delete the Nodequeue relationship. The View also uses Views Carousel module, which you may need installed in order to import the View successfully.
You also need Views Carousel installed in order to import this View (only tested with 6.x-1.x-dev version).
At the Blocks administration page (admin/build/block), the Recent Projects block is added into the custom home_sidebar region that appears on the home page.
Simplified view: Lower on this page below the first Views import code, I've included a copy of the View with the Nodequeue relationship removed, and the display Style set simply to Unformatted instead of Views Carousel - this nearly removes any aspect of the View worth showing, though I'm including it as some people have requested it. If you do want the Views Carousel, you can simply change the Style back.
$view = new view;
$view->name = 'music';
$view->description = 'Music';
$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('relationships', array(
'nodequeue_rel' => array(
'label' => 'queue',
'required' => 0,
'limit' => 1,
'qids' => array(
'4' => 4,
'1' => 0,
'2' => 0,
'3' => 0,
),
'id' => 'nodequeue_rel',
'table' => 'node',
'field' => 'nodequeue_rel',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'field_media_image_fid' => array(
'label' => '',
'link_to_node' => 0,
'label_type' => 'none',
'format' => 'video-image_linked',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_media_image_fid',
'table' => 'node_data_field_media_image',
'field' => 'field_media_image_fid',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
),
));
$handler->override_option('sorts', array(
'position' => array(
'order' => 'ASC',
'id' => 'position',
'table' => 'nodequeue_nodes',
'field' => 'position',
'relationship' => 'nodequeue_rel',
),
));
$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',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'media' => 'media',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('title', 'Music');
$handler->override_option('items_per_page', 0);
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
'teaser' => 1,
'links' => 1,
'comments' => 0,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('style_plugin', 'viewscarousel');
$handler->override_option('style_options', array(
'skin' => 'tango',
'vertical' => 0,
'start' => '1',
'scroll' => '1',
'visible' => 0,
'animation' => '0',
'easing' => '',
'auto' => '0',
'wrap' => '0',
));
$handler->override_option('row_options', array(
'teaser' => 0,
'links' => 0,
'comments' => 0,
));
$handler->override_option('path', 'music');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler = $view->new_display('block', 'Recent projects', 'block_1');
$handler->override_option('fields', array(
'title' => array(
'label' => '',
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
'field_media_image_fid' => array(
'label' => '',
'link_to_node' => 0,
'label_type' => 'none',
'format' => 'latest-projects_linked',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_media_image_fid',
'table' => 'node_data_field_media_image',
'field' => 'field_media_image_fid',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
));
$handler->override_option('title', 'Recent Projects');
$handler->override_option('footer', '<a href="/music">View more recent projects</a> »');
$handler->override_option('footer_format', '1');
$handler->override_option('footer_empty', 0);
$handler->override_option('items_per_page', 3);
$handler->override_option('row_plugin', 'fields');
$handler->override_option('row_options', array());
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);Views import without Nodequeue or Views Carousel (see info)
$view = new view;
$view->name = 'music1';
$view->description = 'Music';
$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(
'field_media_image_fid' => array(
'label' => '',
'link_to_node' => 0,
'label_type' => 'none',
'format' => 'video-image_linked',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_media_image_fid',
'table' => 'node_data_field_media_image',
'field' => 'field_media_image_fid',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
),
));
$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',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'media' => 'media',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('title', 'Music');
$handler->override_option('items_per_page', 0);
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
'teaser' => 1,
'links' => 1,
'comments' => 0,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('style_options', NULL);
$handler->override_option('row_options', array(
'teaser' => 0,
'links' => 0,
'comments' => 0,
));
$handler->override_option('path', 'music');
$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,
));
Hi David,
Thanks so much for you helpful Drupal site. It really has gotten me past a few roadblocks as I am figuring out Drupal.
I have a question about importing your View for your custom media type. I tried importing it, and got the error message that the style plugin Viewscarousel is not available. Is this something that can be obtained on the WWW?
Best Regards
Brian Daly
doh, please ignore my last question, I missed that Viewscarousel is a module listed right on your modules used list!
Hi Brian -
No worries :) I actually should have clarified before that Views Carousel would probably be needed as well in order to import. I added a note now to the text above, and will post (for those who need it) a more generalized version of the View in the near future.