1

I would like to be print for the first row in different display style for the image field. Thx all!

<div class="row first">
    <h3>Title1</h3>
    <img class="this is the first image with specific style of output"/>
</div>
<div class="row">
    <h3>Title2</h3>
    <img class="standard style output"/>
</div>
<div class="row">
    <h3>Title3</h3>
    <img class="standard style output"/>
</div>
<div class="row last">
    <h3>Title4</h3>
    <img class="standard style output"/>
</div>

I tried using the php field. Something like:

<?php
  if ($view->row_index == 0) {
    print $row->field_foto_principale;
  } else {
    print "other";
  }
?>

But I can not render the image.

  • You can use the attachment feature of views. Which you can positioned above the block. So that attachment will be your first raw, and whatever you want you can do without affecting others. – CodeNext Jul 17 '16 at 17:21
  • is this for Drupal 7 or 8? – No Sssweat Jul 18 '16 at 1:47
  • Hi @No Sssweat. I use Drupal 7. I do not know attachment feature. Can you tell me about it? – Daniele Jul 19 '16 at 9:21
  • If I understood correctly, you want to change CSS of first row the way you want without affecting other rows? – CodeNext Jul 19 '16 at 20:05
1

you can also use hook

function HOOK_preprocess_views_view_fields(&$vars) {
  if ($vars['view']->name == 'your_view_name' && $vars['view']->row_index == 1) {
    // your code
  }
}
0

At the moment I'm using this code in a Custom PHP field:

<?php
    if ($view->row_index == 0) {
        $img_url = $data->field_field_foto_principale[0]['rendered']['#item'][uri];
        $style = $data->field_field_foto_principale_1[0]['rendered']['#image_style'];
    } else {
        $img_url = $data->field_field_foto_principale[0]['rendered']['#item'][uri];
        $style = $data->field_field_foto_principale[0]['rendered']['#image_style'];
    }
?>
<img src="<?php print image_style_url($style, $img_url) ?>" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.