Hi,
I have a view which displays news articles in the format of title + date in a list. I am now trying to change the first item in the list to display title + date + image + body + url. I have listed the image + body + url as hidden in the view settings, and would like a way of referencing them from the views-view-list.tpl.php file. I am not sure what is the best way of going about this, my code is below. Many thanks!!
**Further to this question.. If I have more than one view I guess I don't want to be modifying the views-view-list.tpl.php file - is there a better way to customise the views?
------------------------------------------------------------------------
/**
* @file views-view-list.tpl.php
* 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
*/
foreach ($rows as $id => $row) {
// ****** $fields['field_name']->content --> realise this does not work *******
// first news article display more details
print "<div><div class='thumb'><img title=" . $fields['field_imgtitle']->content . "id='article-image' src='" . $fields['field_imgsrc']->content . "'></div>";
print "<p class='bold'>" . $row . "</p>";
print "<p>" .$fields['body']->content . "<a title='Read more' href='". $fields['field_docurl']->content . "'>Read more ></a></p></div>";
break;
}
print $wrapper_prefix;
More news
if (!empty($title)) :
print $title;
endif;
print $list_type_prefix;
$i = 0;
foreach ($rows as $id => $row) {
if ($i == 0) {
//do nothing
} else {
print "<li class=" . $classes_array[$id] . ">" . $row . "</li>";
}
$i++;
}
print $list_type_suffix;
print $wrapper_suffix;
Comments
have I put this in the wrong
have I put this in the wrong section?
Same question
Hi, I'm looking for almost the same thing, but haven't figured it out yet... In my case I am looking for a way to add a field value as the class of the <li> tag.
I do know how to make this a view-specific override. Check the theme information from the view configuration page, you can see that you can use views-view-list--VIEW-NAME.tpl.php in stead of views-view-list.tpl.php.
I think that we should make use of the template preprocess function to change the data, but I haven't figured out how...
On the side note: Maybe there is another solution to your problem. Don't hide the fields but show them everywhere, and then use CSS to hide te fields in all rows but the first. The first row has the class "views-row-first" so there is a way to apply specific formatting to the first item.
Heui Chris, Have you checked
Heui Chris,
Have you checked semantic_views? IIRC, that module has support for stuff like, first, last,zebra, N'th, etc...
ezCompany | DIY-Layout | TANK86
I'm not sure what the
I'm not sure what the official drupal way would be, but there are two ways I can think of that aren't too complicated.
1) The absolute easiest way:
Just make a second view that has the picture and body, and embed it at the top of your view (Views 3 has a built in mechanism for this)
2) I believe by default views will put a "first" class on the first row. You can just hide the information via css for all of the entries but the first one.
Otherwise modifying the template would work too, just make sure you name the template file correctly to not interfere with the other views.
That's all I have off the top of my head, I hope it helps.