By BogenDorpher on
I want to add a custom class inside a views row output based on the content type of that row. For example, I have a view that outputs "stories", "reviews", and "announcements". Those are my three content types.
Unfortunately, the following is outputted by default:
<div class="view-content">
<div class="views-row views-row-1 views-row-odd views-row-first">
<div class="views-row views-row-2 views-row-even">
<div class="views-row views-row-3 views-row-odd">
<div class="views-row views-row-4 views-row-even">
I would like for the following to be displayed:
<div class="view-content">
<div class="views-row views-row-1 views-row-odd views-row-first"> <div class="story sticky"></div>
<div class="views-row views-row-2 views-row-even"> <div class="story"></div>
<div class="views-row views-row-3 views-row-odd"> <div class="review"></div>
<div class="views-row views-row-4 views-row-even"> <div class="story"></div>
I have tried editing the views-view-unformatted.tpl.php file but I cant figure out the proper function to print the content type. Print $type; does not work.
Comments
add content type in the
add content type in the fields, and print it in the tpl file.
example: if Node title,Node id, and Node posted date are my fields in my views, just add Node type also and then ,
try to print $data (which will have all the views result) and u can check whether the result is having the Node type or not.
How do I call the Node Type
How do I call the Node Type function inside my tpl file (views-view-unformatted.tpl.php)? I have the Node Type field set to "exclude from display"
Did u try printing the output
Did u try printing the output through print_r();
example,
drupal_set_message('
');
I am not sure output variable is $output or $rows,
Or simply try print print_r(array_keys(get_defined_vars()), 1);
If u r able to get the result printed in above format then, u can take the Node type also from there,if u r unable to find it, let me know the output of the above code,(My only doubt is $output or $rows ,which one will give the result).
where do I do this at?
where do I do this at?
inside your View tpl.php
inside your View tpl.php
jk, thank you so far! This is
jk, thank you so far! This is a bit old, but
drupal_set_message(''.print_r($rows,1).'');does print out the content type amongst the other fields. How can I let print out only the content type? And since i want to put it as a css class it would be good to have the machine-readable name printed.Thanks!