I have a view that has a filter to only pull results from 2 content types. I would like each views entry to have a class that shows the content type of the node. How can I do it?
You can add that into the views fields template for the row or you can add a node type field to your view, and make sure it's first or before the field you want to add the class to, and disable its display. Then, you can go to the field you want to add the type class to, select rewrite output, and use the contents of this first field as a replacement value in the class of the wrapper element.
Just rereading, the above just wraps a field in your row. To put that class in the row's html, you could edit up
views-view-fields.tpl.php for your specific view and add a div wrapper yourself with that information in it (grab it all out of the $row variable provided). Keep the node type field in there but have it not displayed.
So, for example, if your view is named foo, you could create a
views-view-fields--foo.tpl.php with this in it:
<div class="<?php print $row->node_type; ?>"> <?php foreach ($fields as $id => $field): ?> <?php if (!empty($field->separator)): ?> <?php print $field->separator; ?> <?php endif; ?> <?php print $field->wrapper_prefix; ?> <?php print $field->label_html; ?> <?php print $field->content; ?> <?php print $field->wrapper_suffix; ?> <?php endforeach; ?> </div>
where, if I am cutting and pasting right today, the only thing I've added is the opening div and closing div. This then wraps your whole row in your own div with class of nodetype.
You can find all of these templates in the views style information area (make sure your views code matches mine). Just save them in or under your theme directory.
If you want to have the class in
<div class="views-row views-row-2 views-row-even...."> instead of adding another
<div class="...."> inside it, you can copy
views-view-unformatted.tpl.php to one appropriately named for your view and grab the information needed for the node-type out of the
$view variable there. You could also use a views_preprocess() function to do it, although for stuff like this I like seeing it in the template, but that's just me. The function should be
mythemeormodulename_preprocess_views_view_unformatted(&$vars) and you can add or modify any of the vars you want, once again, since $view is present, all the information about the view is as well. For ideas, check out the views code in
sites/all/modules/views/theme/theme.inc, or where ever module code is stored on your machine.