When the search results are themed by providing odd / even classes (aka zebra stripes) the parity is often not correct. This is especially apparent when grouping the search results by type. In this case the zebra stripes will just keep alternating, instead of resetting to 'odd' when showing the first result of a group.
This can also occur when displaying non-grouped results: if a node is displaying before the search results, the first result will incorrectly be given the 'even' class.
To see this happening you will need to make sure the default zebra stripes are output in the node:
function THEMENAME_preprocess_node(&$variables) {
// Add zebra striping to nodes.
$variables['classes_array'][] = $variables['zebra'];
}
Comments
Comment #1
pfrenssenComment #2
swentel commentedWuu, you're on a roll :) I don't have much to review this week, but I see no reason for this to not go in, so expect a commit next week or so.
Comment #3
pfrenssenNo problem, you are already very much on the ball with reviewing and committing patches. Thanks for the great work, I really love Display Suite!!
Comment #4
swentel commentedDid a quick test and this works great!
Some thoughts about the template_preprocess_node() function:
I'll let this sink for a bit this week - need to test this quick with the apachesolr backend as well, although I don't expect any problems.
Comment #5
pfrenssenThis patch needs work indeed. I made this backwards, starting from the template_preprocess_node().
If we simply replace the
$node->ds_search_parityvariable with$node->zebrathere is possibly no need for template_preprocess_node(). I have to look into this though, it depends on how theme() handles the zebra stripes. If I remember correctly it is using an internal static variable to keep the count.Using zebra stripes on nodes is not something that is often needed on regular pages, but I suppose this is rather common for search results. We could make this an option in the search configuration: 'Add odd/even CSS classes to the search results.' This would save themers the work to implement the hook.
Regarding breaking other implementations: this is tricky, but I suppose if there is a need for two separate sets of zebra-striped nodes on one page this would have to be done with custom functionality anyway. Since the number of search results can not be predicted, any subsequent nodes have a 50/50 chance of starting with 'odd' or 'even', depending on the number of results returned.
Comment #6
pfrenssenThe zebra striping are done with a static variable so we have no way of overriding that (see template_preprocess()). This problem also affects other modules such as Views (see #360550: how to reset $zebra/$id for each instance of a view).
The only solution seems to be to provide a second variable as in the patch above. Providing our own template_preprocess_node() hook is indeed not desirable, as it will override any zebra striping on pages that display search results. We should leave this for the themer to implement.
A more recognisable variable name would also be nice (ds_search_zebra?).
Comment #7
pfrenssenReworked patch. This adds a new 'ds_search_zebra' property to the node object.
A typical way to use this would be in template.php:
Comment #8
swentel commentedCommitted to restructure branch, thanks!