This is pretty simple. All you need to do is go through following steps, which will let you create a same type of view which I have created on my system: The trick is to use relationship from field_image.
- Create a simple view of articles (I created page), by default this will have a field_image. I am exporting a view below, import it.
- In theme information override style output from "views-view-list.tpl.php". I am attaching code for both.
View:
$view = new view(); $view->name = 'article_view'; $view->description = ''; $view->tag = 'default'; $view->base_table = 'node'; $view->human_name = 'Article View'; $view->core = 7; $view->api_version = '3.0'; $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ /* Display: Master */ $handler = $view->new_display('default', 'Master', 'default'); $handler->display->display_options['title'] = 'Article View'; $handler->display->display_options['use_more_always'] = FALSE; $handler->display->display_options['access']['type'] = 'perm'; $handler->display->display_options['cache']['type'] = 'none'; $handler->display->display_options['query']['type'] = 'views_query'; $handler->display->display_options['exposed_form']['type'] = 'basic'; $handler->display->display_options['pager']['type'] = 'full'; $handler->display->display_options['pager']['options']['items_per_page'] = '10'; $handler->display->display_options['style_plugin'] = 'list'; $handler->display->display_options['row_plugin'] = 'fields'; $handler->display->display_options['row_options']['default_field_elements'] = FALSE; /* Relationship: Content: Image (field_image:fid) */ $handler->display->display_options['relationships']['field_image_fid']['id'] = 'field_image_fid'; $handler->display->display_options['relationships']['field_image_fid']['table'] = 'field_data_field_image'; $handler->display->display_options['relationships']['field_image_fid']['field'] = 'field_image_fid'; /* Field: Content: Title */ $handler->display->display_options['fields']['title']['id'] = 'title'; $handler->display->display_options['fields']['title']['table'] = 'node'; $handler->display->display_options['fields']['title']['field'] = 'title'; $handler->display->display_options['fields']['title']['label'] = ''; $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; $handler->display->display_options['fields']['title']['element_label_colon'] = FALSE; /* Field: File: Path */ $handler->display->display_options['fields']['uri']['id'] = 'uri'; $handler->display->display_options['fields']['uri']['table'] = 'file_managed'; $handler->display->display_options['fields']['uri']['field'] = 'uri'; $handler->display->display_options['fields']['uri']['relationship'] = 'field_image_fid'; $handler->display->display_options['fields']['uri']['label'] = ''; $handler->display->display_options['fields']['uri']['element_label_colon'] = FALSE; /* Sort criterion: Content: Post date */ $handler->display->display_options['sorts']['created']['id'] = 'created'; $handler->display->display_options['sorts']['created']['table'] = 'node'; $handler->display->display_options['sorts']['created']['field'] = 'created'; $handler->display->display_options['sorts']['created']['order'] = 'DESC'; /* Filter criterion: Content: Published */ $handler->display->display_options['filters']['status']['id'] = 'status'; $handler->display->display_options['filters']['status']['table'] = 'node'; $handler->display->display_options['filters']['status']['field'] = 'status'; $handler->display->display_options['filters']['status']['value'] = 1; $handler->display->display_options['filters']['status']['group'] = 1; $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE; /* Filter criterion: Content: Type */ $handler->display->display_options['filters']['type']['id'] = 'type'; $handler->display->display_options['filters']['type']['table'] = 'node'; $handler->display->display_options['filters']['type']['field'] = 'type'; $handler->display->display_options['filters']['type']['value'] = array( 'article' => 'article', ); /* Display: Article List */ $handler = $view->new_display('page', 'Article List', 'article_list'); $handler->display->display_options['path'] = 'article-view';
Now the overridden template:
<?php /** * @file * Default simple view template to display a list of rows. * * - $title : The title of this group of rows. May be empty. * - $options['type'] will either be ul or ol. * @ingroup views_templates */ ?> <?php print $wrapper_prefix; ?> <?php if (!empty($title)) : ?> <h3><?php print $title; ?></h3> <?php endif; ?> <?php print $list_type_prefix; ?> <?php foreach ($rows as $id => $row): ?> <li class="<?php print $classes_array[$id]; ?>" style="background-image:url(<?php print file_create_url($view->result[$id]->file_managed_field_data_field_image_uri); ?>);"><?php print $row; ?></li> <?php endforeach; ?> <?php print $list_type_suffix; ?> <?php print $wrapper_suffix; ?>
This will do the trick for you. Let me know if you face some issues.