I have created a view and it gives me lots of default css classes for the rows of my unformatted list. I have added the token [type] in the style options for the page under 'Row class'. So now my list items are wrapped in the following div:
<div class="views-row views-row-1 views-row-odd views-row-first article"></div>
You can see the class 'article' is added according to the node's content type. But, I need to give specific rows, like the third occurence of class 'article' row, their own 'static' unique css classes, like:
<div class="views-row views-row-1 views-row-odd views-row-first article my-class"></div>
views-row-[number] will not do because it changes depending on how many rows there are in the view (not always the same in this view) i.e. the third from last row will sometimes be views-row-10, sometimes it will be views-row-13. How do I find out what other tokens are available to me (I'm looking for ones that will create unique classes), or is there another way that I can create a unique, unchanging, class?
I have tried using pseudo css classes to target the desired rows, like :nth-of-type(N).
Solution
To make classes unique, append an incrementing number to the required classes with jQuery. CSS pseudo class selectors are helpful too, as are tokens. There does not seem to be one solution that will fit every situation: a mix of approaches is required.
Add to template.php in your theme's root folder (or how ever you want to implement your jQuery):
/**
* Implements template_preprocess_views_view().
*/
function YOURTHEME_preprocess_views_view(&$vars) {
$view = $vars['view'];
if ($view->name == 'VIEWNAME') {
drupal_add_js('
(function($) {
$(function() {
$("div.article").removeClass("article").addClass(function(index) {
return "article-" + index;
});
});
})(jQuery);
', 'inline');
}
}